我有一種方法,我嘗試通過LINQ查詢返回一些數據庫結果,但是Visual Studio不允許我使用select語句。這是我到目前爲止有:不能在LINQ查詢中使用select
public static int GetCurrentUserDepartmentId(Guid userGuid)
{
int departmentId = -1;
using (PTMS_DataEntities entities = new PTMS_DataEntities())
{
var userDepartment = from employee in entities.Employees
join user in entities.aspnet_Users
on employee.User_Id equals user.UserId
where employee.User_Id equals userGuid
departmentId = (int)userDepartment;
}
return departmentId;
}
然而,在LINQ段,我會像它到如下:
from employee in entities.Employees
join user in entities.aspnet_Users
on employee.User_Id equals user.UserId
where employee.User_Id equals userGuid
select employee.Department_Id
有,爲什麼我不是一個特別的原因被允許添加最後的選擇部分?
你的意思是說你沒有得到intellisense中的select方法嗎? – 2013-03-04 17:11:23
正確。當我嘗試手動添加它時,它也不喜歡它。 – 2013-03-04 17:12:53
是命名空間System.Linq添加在頂部? – 2013-03-04 17:13:30