我发现了一个确切的问题,但没有正确答案。
点击here
"我想过滤掉"父对象哪些子符合符合条件。父母不应该只返回那些符合标准的孩子。"
按照sql查询我要转换lambda:
SELECT
*
FROM
RO
INNER JOIN
ROE
ON ROE.ROId = RO.Id
WHERE RO.TreeNode LIKE '.66.%' AND ROE.EnvironmentId = 3
我是工作实体框架。我有两个实体:RO和ROE,遵循实体结构:
public class RO
{
int ROId {get; set}
string ROName {get; set}
string TreeNode {get; set}
EntityCollection<ROE> ROEs {get; set}
}
public class ROE
{
int ROEId {get; set}
int ROId {get; set}
int environmentId {get; set}
string ROName {get; set}
}
我希望过滤的RO对象具有TreeNode StartsWith&#39; .66。&#39; AND children符合条件EnvironmentId = 3.但返回一个List,每个RO都有过滤List。
我正在尝试:
var ros = ROs.Where(ro => ro.TreeNode.StartsWith('.66.') &&
ro.ROEs.Any(roe => roe.EnvironmentId == environmentId))
但是这个表达不起作用,因为ROE Collection没有被过滤。
我的问题得到了解答。但我的问题是&#34;包括&#34;因为当我尝试恢复一些子集合时它不起作用。例如:
var ros = context.ROS.Include("T").Include("T.TOEs").Include("ROEs.EL")
.Where(ro => ro.TreeNode.StartsWith('.66.'))
.Select(ro => new
{
ro,
// "T" Object is working, but the child collection "T.TOEs" isn't working
T = ro.T,
// "ROEs" Collection is working, but the child collection "ROEs.EL" isn't working
ROEs = ro.ROEs.Where(roe => roe.EnvironmentId == environmentId)
})
.AsEnumerable()
.Select(x => x.ro)
.ToList();