Linq to Entities 查询帮助
我正在尝试增加对 linq 的了解,因此我想在不使用存储过程的情况下创建以下查询,但我不太确定如何构建它。
如果我有三个表/实体:
Farmer (FarmerId, BusinessTitle)
Produce (ProduceId, ProduceTitle)
FarmerProduce (FarmerId, ProduceId)
我会怎样执行搜索 BusinessTitle & 的查询ProduceTitle 针对特定单词(例如 Raspberry)并返回 Farmer 实体列表。
我可以分别对任一 Farmer of Produce 进行搜索,例如:
var query = (from f in farmer
where f.BusinessTitle.Contains("raspberry")
select l).ToList();
var query = (from fp in FarmerProduce
where fp.Produce.ProduceTitle.Contains("raspberry")
select fp.Farmer).ToList();
但我不确定如何将 FarmerProduce “查找表”合并到单个查询中。
I am trying to increase my knowledge of linq so I would like to create the following query without using a stored procedure but I am not really sure how to structure it.
If I have three table/entities:
Farmer (FarmerId, BusinessTitle)
Produce (ProduceId, ProduceTitle)
FarmerProduce (FarmerId, ProduceId)
How would I do a query that searched the BusinessTitle & ProduceTitle for a particular word (say Raspberry) and returned a list of Farmer entities.
I can achieve a search on either Farmer of Produce separately e.g.:
var query = (from f in farmer
where f.BusinessTitle.Contains("raspberry")
select l).ToList();
var query = (from fp in FarmerProduce
where fp.Produce.ProduceTitle.Contains("raspberry")
select fp.Farmer).ToList();
But I am unsure how to combine the FarmerProduce "lookup table" into a single query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从外观上看,这应该是 linq 中的一个简单的 OR。
添加了独特。
This one should be a simple OR in linq by the looks of it.
Added Distinct.
如果您只需要农民:
假设多对多作为
Produces
导航属性导入。If you only need the farmers:
Assuming the many-to-many was inported as a
Produces
navigation property.