Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 0.69 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to return DateTimeOffset type with Linq
  2. public DateTimeOffset GetLastDate(Guid Id, Guid AppId)                    
  3. {
  4.    var q = from k in context.Inspections
  5.            where k.Id == Id || k.AppId == AppId
  6.            select k.Duedate;
  7.    return q;
  8. }
  9.        
  10. var q = from k in context.Inspections
  11.             where k.Id== Id||k.AppId== AppId
  12.             select k.Duedate;
  13.     DateTimeOffset? value = q.First();
  14.  
  15.     if (value.HasValue)
  16.         return value.Value;
  17.     else // found NULL in DB! Do something in this case...
  18.         throw new ApplicationException("Null offset found");
  19.  
  20.     // Alternatively, you could use some default value (this uses "Now"):
  21.     // return value ?? DateTimeOffset.Now;