如何将sql查询更改为LINQ

时间:2014-11-13 07:20:36

标签: sql linq

如何将以下sql查询更改为LINQ

select top(5) * 
from Tradingdays 
where Trading_date <'2014-10-16 00:00:00.000' 
  and holiday !=1 
order by id desc

1 个答案:

答案 0 :(得分:1)

DateTime yourDate = new  DateTime(2014,10,16,0,0,0,0);   
var list = (from t in datacontext.TradingDays
            where t.Trading_date < yourDate && t.holiday != 1
            orderby t.id desc
            select t).Take(5);