我想将LINQ联接转换为简单的SQL内联联接查询。
这是我的LINQ查询。
int CompanyId = Convert.ToInt32(HttpContext.Current.Session["CompanyId"]);
list = (
from p in db.Projects
join pl in db.ProjectTaskLists on p.ProjectID equals pl.ProjectID
where pl.IsDeliverable == true && p.CompanyId == CompanyId
select new {
ProjectID = p.ProjectID,
ProjectName = p.ProjectName + " - " + p.ProjectCode
}
).ToList<object>();
return list;
答案 0 :(得分:3)
这等效于SQL
:
select p.ProjectID ProjectID, p.ProjectName + ' - ' + p.ProjectCode as ProjectName
from
Projects p join ProjectTaskLists pl
on p.ProjectID = pl.ProjectID
where pl.IsDeliverable = true and p.CompanyId = @CompanyId
其中@CompanyId
是一个参数。
答案 1 :(得分:1)
这是SQL Normal查询:
select p.ProjectID, p.ProjectName + ' - ' + p.ProjectCode as ProjectName from Projects p
Inner join ProjectTaskLists pl on pl.ProjectID = p.ProjectID
where pl.IsDeliverable == true && p.CompanyId == @CompanyId