public class Parent
{
public int ParentId { get; set; }
public string ParentPropertyA { get; set; }
public string ParentPropertyA { get; set; }
public List<Child> Children{get; set;}
}
public class Child
{
public int ChildId { get; set; }
public string ChildPropertyA { get; set; }
public string ChildPropertyB { get; set; }
}
private static Expression<Func<Parent, dynamic>> BuildModel()
{
return x => new
{
x.ParentId,
x.Children
};
}
我在上使用此表达式
IQueryable.Select(BuildModel())
假设我有一个
Parent
具有两个的对象
Children
...
考虑到这种结构,我如何实现返回两条记录
父母亲
属性和特定
儿童
,而不仅仅是一个
父母亲
有两个
儿童
?
例子:
{
ParentId: 1,
ParentPropertyA: "parentA",
ParentPropertyB: "parentB",
Children:
[
{
ChildId: 1,
ChildPropertyA: "childA1",
ChildPropertyB: "childB1"
},
{
ChildId: 2,
ChildPropertyA: "childA2",
ChildPropertyB: "childB2"
}
]
}
相反,我想让他们返回为:
[
{
ParentId: 1,
ParentPropertyA: "parentA",
ParentPropertyB: "parentB",
ChildId: 1,
ChildPropertyB: "childB1"
},
{
ParentId: 1,
ParentPropertyA: "parentA",
ParentPropertyB: "parentB",
ChildId: 2,
ChildPropertyB: "childB2"
}
]
这可能吗?谢谢