linq - Linq 哪里过滤
问题描述
查询结果过滤有问题。
public class LinkTabProductCategory
{
[Key]
public int Id { get; set; }
public int ProductId { get; set; }
[JsonIgnore]
public Product Product { get; set; }
public int CatalogSubSectionId { get; set; }
public CatalogSubSection CatalogSubSection { get; set; }
}
var result = DataContext.Product
.Include(o => o.Offers)
.ThenInclude(p => p.Prices)
.ThenInclude(t => t.Type)
.Include(p => p.Brand)
.Include(tb=>tb.LinkTabProductCategories)
.Where( p=>p.LinkTabProductCategories **???** == id)
.ToList();
我需要获取具有以下内容的产品列表: LinkTabProductCategories.CatalogSubSectionId == id
更新 这是查询结果列表:
{
"ProductId":"",
"UID1C": "",
"Name": "",
"Article": "",
"FactoryNumber": "",
"Brand": {
"BrandId": "",
"UID1C": "",
"Name": ""
},
"Offers": []
,
"LinkTabProductCategories": [
{
"Id": 1,
"ProductId": 2,
"CatalogSubSectionId": 1,
"CatalogSubSection": null
}
]
},
{},
{}.....
如何仅使用“CatalogSubSectionId”== 1 获取产品
解决方案
使用方法 Any(predicate) — 返回 true,任何元素满足条件谓词:
.Where(p => p.LinkTabProductCategories.Any(c => c.CatalogSubSectionId == id))
推荐阅读
- reactjs - 快速回复新闻功能(有天赋的聊天)反应原生
- javascript - 确定 Kendo UI 控件的类型
- java - java - 修改并返回一个buffredInputStream
- r - ggplot2 - 用一列绘制 Y 轴,但从另一列标记
- kotlin - 既然我们已经有了 Map、List 和 Array 的大小,那么 count() 有什么用?
- database - 加速 Access 数据库
- scala - 访问映射函数内的 scala 列表的索引和值
- node.js - 对 Revolut API 进行身份验证
- r - 删除有条件的行
- alfresco - 允许用户在 Alfresco Share 中保存查询/搜索参数