简体   繁体   中英

How to use two different database with relation in one asp.net mvc c# application

如何在一个ASP.NET MVC C#应用程序中使用两个具有关系的不同数据库

One of the benefits of using Entity Framework 4.0 is that it can handle data from multiple tables, or as in your case, multiple databases. Here is one how-to article . There is somewhat of a learning curve, but many people like this approach, and Microsoft seems to be dedicated to it for the future.

Basically, using EF allows you to do the data mapping in its model, abstracting all the database and table joins from you. You get business objects with class and property names that you can understand, and that are easier to code against.

static New table1DataContext Context1 = new table1DataContext ("ConnectionString1"); static table2DataContext Context2 = new table2DataContext ("ConnectionString2");

//Linq statement in c#

var query = from a in table1DataContext.table1 from b in table2DataContext.table2 where a.ID == b.ID
select new { a, b };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM