linq to sql 查询问题
我的查询语句:
DateTime dt = new DateTime(1900, 1, 1);
var list = (from p in resarchData
join t in times
on p.workCls equals t.WorkCls into g
from r in g.DefaultIfEmpty(new CPM_PJ_PLAN_TIME { ID = 0,PJ_TIME_EDATE = dt, PJ_TIME_SDATE = dt })
select new
{
code = p.code,
workCls = p.workCls,
Item = p.Item,
sDate = r.PJ_TIME_SDATE,
eDate = r.PJ_TIME_EDATE,
comment = r.PJ_TIME_COMMENT,
pid = r.Pid
}
);
t表中有时间就显示,如果没有就不管,repeate绑定的时候就是空白,但是我的查询我给了个默认时间,呈现出来的全是默认时间,没有查出数据库t表的值,如果不给默认的怎么能得到我想要的结果呢?
[解决办法]
DateTime dt = new DateTime(1900, 1, 1); var list = (from p in resarchData join t in times on p.workCls equals t.WorkCls into g from r in g.DefaultIfEmpty() select new { code = p.code, workCls = p.workCls, Item = p.Item, sDate =r==null?dt : r.PJ_TIME_SDATE, eDate = r==null?dt:r.PJ_TIME_EDATE, comment = r==null?"":r.PJ_TIME_COMMENT, pid = r==null?"":r.Pid } );
[解决办法]
有专门的LINQ版块的:
http://forum.csdn.net/SList/LINQ/