这个东西自己多尝试下能熟练,参考这个:
http://msdn.microsoft.com/zh-cn/library/bb386913.aspx
先实例化 Context
void DoQuery()
{
DemoDataContext ct=new DemoDataContext();
var query= from zt in ct.Zt_Tables
where zt.UserName=='s'
orderby zt.Date
select new{
zt.ID, zt.Date, zt.Time, zt.UserName, zt.ZtID, zt.DaKaType
};
}
不要以SQL的思维去写linq,不要想着把SQL翻译成linq
不知道兄台用的是什么ORM工具?
SELECT ID, Date, Time, UserName, ZtID, DaKaType FROM Zt_Table WHERE (UserName = 's') AND (Date BETWEEN '2010-9-28' AND '2010-10-30') ORDER BY Date
等价于
from val in zt_table where val.UserName='s' && (val.Date >'2010-9-28' &&va l.Date< '2010-10-30') order by val.Date select new{val.ID,val.Date,val.Time,val.UserName,val.ZtID,val.DakaType}