0

I have three different projects which are inter related and now I want to combine all of 'em. All are developed by using MVC.NET code first method. I am confused how to combine all of them? Options I can think of:

  1. Create three 3 dbcontext files and copy paste it from old one respectively.
  2. Use db first method and merge 3 db to another project.

I am not sure how to do it. I'd appreciate if you can suggest any workable method Is it fine if my application has multiple data context and multiple databases? How'd I join tables from it?

Termininja
  • 6,620
  • 12
  • 48
  • 49
Nil
  • 166
  • 2
  • 11

1 Answers1

0

If the data in your application are related to each other, there is no need to use different dbcontexts as the current projects will also be merged. You can continue to use separate entities in the new dbcontext as you used to in the previous contexts. For creating relationships between the tables you might have a look at Configure One-to-Many Relationship and similar ones in Entity Framework Tutorial Pages. After creating the relationships properly you can retrieve data from multiple tables at the same time. In addition to this it would be also better to use ViewModel as explained on What is ViewModel in MAC?. Hope this helps...

Update:

If you want to retrieve data from different database you can try the similar methods to that given below:

SQL Server: Joining Tables from Different Databases on the Same - My Tec Bits

Can we use join for two different database tables?

Querying data by joining two tables in two database on different servers

Community
  • 1
  • 1
Murat Yıldız
  • 11,299
  • 6
  • 63
  • 63
  • Helllo, there is already lots of data in each database ( 3-4GB in eacch) and I have to keep that data into diff database so that it won't grow to 10GB. So, I want to keep the databases separate but query them using joins. I am more confused bcoz it already contains the data and I can't change it's schema all of sudden. Can you suggest me any other way that what you suggested? Anyway, thanks for your previsions answer too, but I don't think it's solving my issue. :) – Nil Apr 24 '16 at 06:04
  • Hey, thanks for your answer, but I still want to know , should I make three diff 3 dbcontext in my project and give 3 diff connection string and data context? Will it be easy for code first migration? And I always mark answer when it works for me, I'll mark it, as soon as it works for me, thanks a lot – Nil Apr 24 '16 at 10:57
  • Yes you should because you need to use 3 different databases and this means you need 3 DbContexts and 3 connectionString for each of them. For migration part, you might have a look at http://stackoverflow.com/questions/10507910/ef-code-first-migration-with-multiple-database-dbcontext. Hope this helps... – Murat Yıldız Apr 24 '16 at 11:05