当我在EF模型上执行lunq查询时,它是否无法获得子实体?我有一个交易表,它有一个收款人链接和一个交易类型实体。此外,每笔交易都有一系列交易行...Linq获取子项目
但是代码的波纹管 - 所有的子对象看起来都是NULL,但实际的实体(Date)中的数据似乎没问题。但在行中:t.account.account_id; ....'account'是NULL。
public static List<AccountTransactionDto> GetTransaction()
{
var trans = (from t in Db.account_transaction
select t).ToList();
List<AccountTransactionDto> al = new List<AccountTransactionDto>();
foreach(var t in trans)
{
AccountTransactionDto a = new AccountTransactionDto();
a.AccountId = t.account.account_id;
a.AccountTransactionId = t.account_transaction_id;
a.PayeeId = t.payee.payee_id;
a.TransactionDate = t.transaction_date;
a.TransactionTypeId = t.z_transaction_type.transaction_type_id;
foreach(var tl in t.account_transaction_line)
{
AccountTransactionLineDto l = new AccountTransactionLineDto();
l.AccountTransactionLineId = tl.account_transaction_line_id;
l.Amount = tl.amount;
l.BudgetId = tl.budget.budget_id;
l.CostCenterId = tl.cost_centre.cost_centre_id;
l.SubCategoryId = tl.sub_category.sub_category_id;
a.AccountTransactionLine.Add(l);
}
al.Add(a);
}
return al;
}