2 回答

TA貢獻1816條經(jīng)驗 獲得超6個贊
您收到錯誤,因為您正在將整數(shù)列表 (des) 與單個整數(shù) (SiteID) 在 進行比較。.Where(e => e.SiteID = des);
你可以這樣做:
var employeesSearch = db.Employees.Include(e => e.Area).Include(e => e.Discipline).Include(e => e.Shift).Include(e => e.Site).Where(e => des.Contains(e.SiteID));

TA貢獻1806條經(jīng)驗 獲得超8個贊
此查詢將返回而不是 :IQueryable<int>int
var EmployeeIDCatch = db.Employees.Where(s => s.Email.Equals(name)).Select(s => s.EmployeeID);
你應(yīng)該做的是使用或獲取標量值:SingleOrDefault()FirstOrDefault()
// this query returns int value
var EmployeeIDCatch = db.Employees.Where(s => s.Email.Equals(name)).Select(s => s.EmployeeID).SingleOrDefault();
// returns multiple SiteIDs
var des = (from c in db.SitesPerEmployees where c.EmployeeID == EmployeeIDCatch select c.SiteID);
var employeesSearch = db.Employees.Include(e => e.Area).Include(e => e.Discipline).Include(e => e.Shift).Include(e => e.Site).Where(e => des.Contains(e.SiteID));
作為第一個查詢的替代方法,您可以使用以下命令:
var EmployeeIDCatch = db.Employees.Where(s => s.Email.Equals(name)).FirstOrDefault().EmployeeID;
- 2 回答
- 0 關(guān)注
- 111 瀏覽
添加回答
舉報