【发布时间】:2021-11-08 07:36:39
【问题描述】:
CoreMasterAccount 有许多 CoreSubAccount。 CoreSubAccounts 有许多 CoreCircuits。
目前,https://localhost:5001/odata/CoreMasterAccounts?$top=2&$expand=CoreSubAccounts($expand=CoreCircuits) 返回:
"value": [{
"MasterAccountId": 1,
"ForeignKey": "foreignkey1",
"CustomerName": "Nunya",
"CoreSubAccounts": [{
"SubAccountId": 1,
"MasterAccountId": 1,
"Btn": "630-323-8400",
"CustomerName": "Nunya1",
"CoreCircuits": []
}, {
"SubAccountId": 2,
"MasterAccountId": 1,
"Btn": "630-920-1100",
"CustomerName": "Nunya2",
"CoreCircuits": []
}, {
"SubAccountId": 3,
"MasterAccountId": 1,
"Btn": "708-444-2100",
"CustomerName": "Nunya3",
"CoreCircuits": []
},
我也希望 CoreCircuits 能够填充。这是通过控制器发生的还是与模型有关?仅供参考,CoreCircuits 与 CoreSubAccounts 具有多对一关系,其结构与 CoreSubAccounts 与 CoreMasterAccounts 多对一关系的结构相同,工作正常。
CoreMasterAccount 控制器:
public async Task<ActionResult<IEnumerable<CoreSubAccount>>> GetCoreSubAccounts()
{
return await _context.CoreSubAccounts
.Include(e => e.CoreCircuits)
.ToListAsync();
}
public async Task<ActionResult<IEnumerable<CoreMasterAccount>>> GetCoreMasterAccounts()
{
return await _context.CoreMasterAccounts
.Include(e => e.CoreSubAccounts)
.Include(e => e.CoreInvoices)
.Include(e => e.TxnManualTransactions)
.ToListAsync();
}
CoreSubAccount 控制器:
public async Task<ActionResult<IEnumerable<CoreSubAccount>>> GetCoreSubAccounts()
{
return await _context.CoreSubAccounts
.Include(e => e.CoreCircuits)
.ToListAsync();
}
【问题讨论】:
标签: c# asp.net-core entity-framework-core odata