
Untitled
By: a guest on
Apr 28th, 2012 | syntax:
None | size: 0.69 KB | hits: 16 | expires: Never
How to return DateTimeOffset type with Linq
public DateTimeOffset GetLastDate(Guid Id, Guid AppId)
{
var q = from k in context.Inspections
where k.Id == Id || k.AppId == AppId
select k.Duedate;
return q;
}
var q = from k in context.Inspections
where k.Id== Id||k.AppId== AppId
select k.Duedate;
DateTimeOffset? value = q.First();
if (value.HasValue)
return value.Value;
else // found NULL in DB! Do something in this case...
throw new ApplicationException("Null offset found");
// Alternatively, you could use some default value (this uses "Now"):
// return value ?? DateTimeOffset.Now;