更新时间:2023-02-16 21:45:26
这是我最终解决问题。
它看起来并不像我可以单独使用LINQ实现它,所以我需要通过的结果进行迭代并消除不必要的
It doesn't look like I can achieve it using linq alone so I need to iterate through the results and eliminate the unwanted.
我的查询来获取***对象:
My query to get the top level objects:
var query = this.Context.GlobalListTable
.Where(i => i.ProductListTypeId == productListTypeId)
.Select(i => i.ProductGroupTable)
.SelectMany(i => i.ComponentTables)
.Where(t => t.ComponentTypeId == componentTypeId)
.ToList();
遍历这些结果,并排除不必要的:
Iterate through the results and exclude the unwanted:
foreach (var _globalListTable in query)
{
foreach (var _productTable in _globalListTable.ProductGroupTable.ProductTables)
{
var _exclude = _productTable.ComponentTables.Where(i => i.ComponentTypeId != componentTypeId);
_productTable.ComponentTables = _productTable.ComponentTables.Except(_exclude).ToList();
}
}
return query;
完美的作品,如果不武。
Works perfectly, if not elegantly.