日期:2014-05-20  浏览次数:20749 次

sql转换成linq 急急急
select * from dbo.SwipeHistories as sh INNER join 
dbo.UserSwipeFlows as us on sh.PhysicsCardNo = us.PhysicsCardNo inner join
dbo.ABFlowNodes as sf on us.CurrentFlowNode = sf.ABFlowNodeID inner join
dbo.SwipePoints as sp on sf.PointCode = sp.PointCode where 
sh.CreateDate=(select max(a.CreateDate) from SwipeHistories as a where UserName=sh.UserName) 
order by sh.CreateDate


转换成linq 怎么写

------解决方案--------------------
C# code

var query=from sh in dbo.SwipeHistories
          join us in dbo.UserSwipeFlows  on  sh.PhysicsCardNo equals us.PhysicsCardNo
          join sf in dbo.ABFlowNodes  on us.CurrentFlowNode equals sf.ABFlowNodeID
          join sp in dbo.SwipePoints on sf.PointCode equals sp.PointCode 
          where sh.CreateDate==SwipeHistories.Where(a=>a.UserName== sh.UserName).Select(a=>a.CreateDate).Max()
          orderby sh.CreateDate
          select sh;

//代码手写,谨提供思路参考