c# - Linq join time error -
i'm trying create list using join on table. i've commented out code doesn't work, code need. when run cast date time error. i'm wondering if should trying join data or run subquery of result, can't figure out how do.
if beingseen null want beingseen property in new object null.
any suggestions on right way fill 'beingseen' property?
object patientsnotseen; using (var db = new sydbconn()) { patientsnotseen = (from events in db.events events.clinicid == clinicid && events.statusid != 6 && dbfunctions.truncatetime(events.stime) == dbfunctions.truncatetime(datetime.now) //join beingseen in db.beingseenstatus on events.patientid equals beingseen.patientid caa //from beingseen in caa.defaultifempty() select new { patientid = events.patientid, events.patientname, appointmenttime = events.stime, // beingseen = beingseen.timestarted }).tolist(); }
when uncomment comments , run error:
additional information: cast value type 'system.datetime' failed because materialized value null. either result type's generic parameter or query must use nullable type.
you can use null coalesce
operator:-
beingseen = beingseen.timestarted ?? datetime.minvalue
if timestarted property not nullable
type-cast it:-
beingseen = (datetime?)beingseen.timestarted ?? datetime.minvalue
Comments
Post a Comment