我想創建一個包含幾個子查詢的linq查詢。我創建了查詢似乎是正確的(至少在語法),但我送回到沒有數據和提琴手正顯示出與此查詢錯誤:C#LInq子查詢問題
public IQueryable<vGatekeeperApproval> GetGatekeeperApprovals(string UserName)
{
SystemsFormsDataContext db = new SystemsFormsDataContext();
IQueryable<vGatekeeperApproval> query;
Int32 UserId = GetCurrentUserId(UserName);
bool IsGatekeeperApprover = IsCurrentUserGKApprover(UserName);
string strSysApproverEmail = GetSystemsApproverEmail(UserName);
try
{
query = (from s in db.vGatekeeperApprovals
join r in db.Requests on s.RequestId equals r.Id
where (IsGatekeeperApprover == true || s.OverrideApproverId == UserId)
&& (
(
from u in db.Staffs
where u.GateKeeperArea ==
(from c in db.vGK_DIV_USING_CCs
where c.SEGMENT_CODE ==
(from a in db.Attributes
where a.AttributeItemId== global_COSTCENTRE && a.FormId==s.Id
select a.AttributeValue).FirstOrDefault()
select c.PARENT_CODE_L3
).FirstOrDefault()
select u.Id
).ToList().Contains(UserId)
)
select s
);
}
catch (Exception ex)
{
query = (from s in db.vGatekeeperApprovals
where s.UserId == 0
select s);
//LogEvent("ERROR!" + ex.Message, ex.Source);
}
return query;
}
任何想法是什麼原因造成的問題?有沒有更好的方法來在linq中創建子查詢?
任何幫助將不勝感激。
舒亞
你會得到什麼錯誤? – SLaks