I’ve tried to add a few helper methods to my dbContext class like this
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));
}
But if I call that from my controller I get this exception:
Unable to create a constant value of type 'myNamespace.Models.Company'. Only primitive types or enumeration types are supported in this context.
If i do the exact same thing in in my controller like this:
db.Tools.Where(t => db.Companies.Any(c => user.Company.CompanyGroupId == c.CompanyGroupId && c.Id == t.CompanyId))
it works. What am I doing wrong?
I solved it by using some joins like this: