如何填写具有此类请求的公司列表? include 方法在我的实现中不起作用
var list = await (from d in context.User.Where(x => ids.Contains(x.UserId))
from c in context.Company.Where(x => x.UserId == d.UserId)
select new User()
{
UserId = d.UserId
Companies = c.Select(x => new Company() {}) // - need Lists
}).ToListAsync(token);
如果你想获取用户及其公司,我建议你尝试这个语句
var user = await context.User
.Where(user => user.Id == userId)
.Include(user => user.Companies)
.ToListAsync(token);
var companies = user.Companies;
我认为这里使用 LINQ 是查询数据库的更好方法。