SQL 改成用 Linq 实现。 SELECT c.id, c.CustomersName as name, f.FollowUpTheWay as names, f.NextFollowDate, f.FollowDate, f.id as fid from dbo.Slgl_CustomerReception as c leftjoindbo.Slgl_FollowUpRecords as f on f.id=(select TOP(1)id from dbo.Slgl_FollowUpRecords where CustomersId=c.idandFollowDate<='2011-7-20' order by id DESC) where c.ProjectId= 9 linq句关键点请帮忙注释下,谢谢。
------解决方案-------------------- 小菜。。。 等着。。。。
C# code
var query=from c in dbo.Slgl_CustomerReception
where c.ProjectId==9
let temp= dbo.Slgl_FollowUpRecords.Where(t=>t.CustomersId==c.id && t.FollowDate <= Convert.ToDateTime("2011-7-20")).OrderByDescending(t=>t.id).FirstOrDefault().id
join f in dbo.Slgl_FollowUpRecords
on f.id equals temp into g
from f in g.DefaultIfEmpty()
select new
{
id=c.id,
name=c.CustomersName ,
names=f==null?"":f.FollowUpTheWay,
NextFollowDate=f==null?"":f.NextFollowDate,
FollowDate=f==null?"":f.FollowDate,
fid=f==null?"":f.id
}
------解决方案--------------------