重新附加实体 [英] Re-Attach an Entity

查看:67
本文介绍了重新附加实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到重新附加实体的问题。


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


 

解决方案

您好AN,


Order和Product实体是否包含one-to - 很多关系? 如果是这样,某些产品只能有一个订单实体。 您能否告诉我们您为什么要将单个产品附加到两个不同的订单实体?  


谢谢你们b $ b Lingzhi Sun


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

 

解决方案

Hi AN,

Do the Order and Product entities contain one-to-many relationship?  If so, certain Product could only have one Order entity.  Could you please tell us why do you want to attach a single Product to two different Order entity?  

Thanks
Lingzhi Sun


这篇关于重新附加实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆