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

求一个sql to linq 转换
select ID, Value, Time from TB where Time in (select max(Time) from TB where ID = TB.ID)

------解决方案--------------------
首先,你应该把你的sql写成比较通用的 inner join 语句。
------解决方案--------------------
var datasource=list.select(t=>{return new{t.ID,t.Value,T.Time};}).orderbydesc(o=>o.time).SingleOrDefault();
------解决方案--------------------
引用:
select ID, Value, Time from TB where Time in (select max(Time) from TB where ID = TB.ID)

var query=TB.GroupBy(t=>t.ID).Select(g=>g.OrderBgyDescending(x=>x.Time).First());

------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

select ID, Value, Time from TB where Time in (select max(Time) from TB where ID = TB.ID)

var query=TB.GroupBy(t=>t.ID).Select(g=>g.OrderBgyDescending(x=>x.Time).First());

我写错了,应该是
select ID, Value, Time from TB t where Time in (select max(Time) from TB where ID = t.ID) 


真怀疑你懂不懂sql,还是就是一个传声筒。人家糖糖正确答案都给你了,你还“修正”。