我将林克用于各实体,我只想呼吁数据库获得一些数据。
我有一个账户标本,可以有多个公司参与。 每个公司都有许多地点。 我可以把公司名单拿到账户中,没有任何问题。 问题在于为每个公司找到地点,并将其全部重新纳入账户目标。 我的法典是:
public Account GetAccountByUserId(int userId)
{
IQueryable<Account> oq = _context.Accounts;
oq = oq.Include(x => x.Companies);
oq = oq.Include(x => x.Companies.SelectMany(l => l.Locations); //I was just guessing here, this throws the error below
Account acct = oq.Single(x => x.Users.Any(y => y.Id == userId));
return acct;
}
The error the .SelectMany throws: The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties. Parameter name: path
这甚至可能无法做到,但如果没有另一种方式? 我只想呼吁数据库。