Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everyone,

I'm working on a project where I deal with multiple databases using entity framework. All databases have similar schema.

I've a scenario where I need to store data in one of the database based on one of the property of that object.

Say I've SoldIn integer property that has some integer values of States (Id of State), the product will be sold in so and so State.
What I've done is, I've written multiple methods with multiple contexts for storing the Object values in respective databases.

Now the functionality and business validations are same for all the states, Only the destination database is different.

Can anyone help me in writing the logic of this scenario in C#?

Thanks in advance.

What I have tried:

What I've done is, I've written multiple methods with multiple contexts for storing the Object values in respective databases.
Posted
Comments
Richard Deeming 15-Feb-18 15:00pm    
This seems like a dodgy database design. Rather than storing data from different states in different databases, they should be stored in the same database, using a foreign key relationship to the state. If necessary, you can use SQL Server's partition functions to separate the data for different states if the performance is a problem.

But failing that, you probably need to use a DTO; create the DbContext with the correct connection string based on the property; and then map the DTO to the DB entity on that context.

That then raises the issue of what happens if an entity's "sold-in" state is changed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900