简体   繁体   中英

Linq to Sql outer Join with Timespan

im using L2S and i have to perform one left outer join with VisitFromTime and VisitToTime values 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

确保t.VisitTimeFromt.VisitTimeTo都是时间跨度。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM