开发者

Linq to SQL outer join with Timespan

I'm using L2S and I have to perform one left outer join with VisitFromTime and VisitToTime v开发者_运维百科alues in right table. Code looks like:

from d in db.Doctors
join p in db.plans on d.DoctorID equals p.DoctorID
into temp
from t in temp.DefaultIfEmpty()
select new MyModel
{
   ....
   ....
   VisitTimeFrom = t!=null?t.VisitTimeFrom:new TimeSpan(),
   VisitTimeTo = t!=null?t.VisitTimeTo:new TimeSpan()
}

It gives me runtime exception that explicit conversion from bigint to time is not supported in SQL.


is VisitTimeFrom and VisitTimeTo bigint in the database?

If so surely you want

VisitTimeFrom = t!=null?t.VisitTimeFrom:0,
VisitTimeTo = t!=null?t.VisitTimeTo:0


Make sure t.VisitTimeFrom and t.VisitTimeTo are both timespans.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜