问题描述
我遇到重新附加实体的问题。
E.G: 我有2个Orders实体实例, order1和order2 and products是订单实体的导航属性作为实体集合。
public List< Orders> GetOrders(订单order1,Order order2,int id)
{
List< Orders> orderList = new List< Orders>();
Product product1 = dbContext.ProductsSet.Where(s => s.Category = id).First();
order1.Products.Attach(product1); //将product1附加到order1
orderList .Add(order1);
order2.Products.Attach(product1); //将product1附加到order2
orderList .Add(order2);
return orderList;
}
问题: 在OrderList集合中,product1仅附加到 order2实体,而不是附加到order1实体。有没有办法将product1附加到order1和order2实体?
谢谢,
AN
Iam having an issue with re-attaching entity.
E.G: I have 2 instances of Orders entity, order1 and order2 and products is the navigation propery of order entity as Entity Collection.
public List<Orders> GetOrders(Order order1, Order order2,int id)
{
List<Orders> orderList = new List<Orders>();
Product product1 = dbContext.ProductsSet.Where(s=> s.Category= id).First();
order1.Products.Attach(product1); // Attaches product1 to order1
orderList .Add(order1);
order2.Products.Attach(product1); //Attaches product1 to order2
orderList .Add(order2);
return orderList;
}
Issue: In the OrderList collection product1 is attached only to order2 entity and not to order1 entity. Is there a way to attach product1 to both order1 and order2 entity?
Thanks,
AN
这篇关于重新附加实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!