我试图像这样向我的 dbContext 类添加一些辅助方法
public IQueryable<Tool> GetAllToolsInCompanyGroup(string userName)
{
var user = GetUserByName(userName);
return Tools.Where(t => Companies.Any(c => user.Company.CompanyGroupId == c.CompanyGroupId && c.Id == t.CompanyId));
}
但是如果我从我的控制器调用它,我会得到这个异常:
Unable to create a constant value of type 'myNamespace.Models.Company'. Only primitive types or enumeration types are supported in this context.
如果我像这样在我的控制器中做同样的事情:
db.Tools.Where(t => db.Companies.Any(c => user.Company.CompanyGroupId == c.CompanyGroupId && c.Id == t.CompanyId))
有用。我究竟做错了什么?