我正在尝试做这样的事情:
List<FundEntity> entities = this.tFunds
.Select(f => new FundEntity() {
ID = f.fundID,
Name = f.name,
CapitalCalls = f.tCapitalCalls
.Select(cc => new CapitalCall() {
ID = cc.capitalCallID,
Description = cc.description,
FundEntity = // Should be the newly created Fund Entity object
}).ToList()
}).ToList();
Run Code Online (Sandbox Code Playgroud)
我希望每个Capitalcall对象都有一个返回其FundEntity的引用.如果不创建循环并手动设置每个循环,这是否可行?
List<FundEntity> entities = this.tFunds
.Select(f =>
{
var parent = new FundEntity() {
ID = f.fundID,
Name = f.name,
};
parent.CapitalCalls = f.tCapitalCalls
.Select(cc => new CapitalCall() {
ID = cc.capitalCallID,
Description = cc.description,
FundEntity =parent // Should be the newly created Fund Entity object
});
return parent;
}.ToList()
).ToList();
Run Code Online (Sandbox Code Playgroud)
那应该给你参考.