实体Sql为多对多关系 [英] Entity Sql for a Many to Many relationship
本文介绍了实体Sql为多对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
您需要使用一些这样的linq; / p>
...
使用(YourEntities ye = new YourEntities())
{
产品我的产品= ye.Product.First(p => p.ProductId = idParameter);
var bills = myProduct.Bill.Load();
}
...
这假设您已经使用entitiy框架为您建立一个数据模型。
票据变量将包含与您的产品对象相关的Bill对象的集合。
希望有帮助。
Consider two tables Bill and Product with a many to many relationship. How do you get all the bills for a particular product using Entity Sql?
解决方案
You need to use some linq like this;
...
using (YourEntities ye = new YourEntities())
{
Product myProduct = ye.Product.First(p => p.ProductId = idParameter);
var bills = myProduct.Bill.Load();
}
...
This assumes that you have used the entitiy framework to build a model for you data. The bills variable will hold a collection of Bill objects that are related to your product object.
Hope it helps.
这篇关于实体Sql为多对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文