是否可以使用来自两个不同数据库的两个上下文实体
代码连接到一个实体:
Using one FoodSupplyEntities
using (var contextFood = new FoodSupplyEntities())
{
var _result = (from _FoodSupplyStatus in contextFood.FoodSupplyStatus
join _FoodQualityStatus in contextFood.FoodQualityStatus
但是是否可以从另一个服务器的不同实体加入另一个表。?
示例(不知道,但它可能像这样。)
using (var contextFood = new FoodSupplyEntities() and contextKitchenware = new KitchenwareEntities() )
{
var _result = (from _FoodSupplyStatus in contextFood.FoodSupplyStatus
join _KitchenwareSupplyStatus in contextKitchenware.KitchenwareSupplyStatus
答案 0 :(得分:0)
假设您在2个不同的数据库中有2个表:
我创建了2个不同的上下文。 现在我将为2个不同的上下文创建2个查询,并将在UserId和OrderedBy上加入这些查询,如:
List<OrderDetails> GetOrderDetails()
{
var users = this.TestDb1ModelUnit.GetRepository<User_Login>().GetAll();
var orders = this.TestDb2ModelUnit.GetRepository<OrderDetail>().GetAll();
var orderDetails = users.Join(orders,
usr => usr.User_Id,
ord => ord.OrderedBy,
(usr, ord) => new { usr, ord }
).ToList();
}