UserAuthorizations表具有公司每用户明智,我想获得分配给他们的用户的公司列表。
// GET: odata/Companies/GetUserCompanies
[EnableQuery]
public IQueryable<UserAuthorization> GetUserCompanies()
{
List<int> userCompanyIds = db.UserAuthorizations.Where(u => u.Cwid == this.UserId).Select(s => s.CompanyId).ToList();
return db.Companies.Where(m => m.Id.ToString().Contains(userCompanyIds));
}
对于上面我得到的错误就像
Cannot convert from 'System.Collections.Generic.List<int>' to 'string'
答案 0 :(得分:5)
试试吧
public IQueryable<Company> GetUserCompanies()
{
List<int> userCompanyIds = db.UserAuthorizations.Where(u => u.Cwid == this.UserId).Select(s => s.CompanyId).ToList();
return db.Companies.Where(m => userCompanyIds.Contains(m.Id));
}