code_junkie

Linq to SQL: add a custom column and the Order By it

Nov 14th, 2011
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. SELECT *, ISNULL(DueDate, DATEADD(year, 10, GETDATE())) AS DueDateForSorting
  2. FROM Tasks
  3. ORDER BY DueDateForSorting
  4.  
  5. SELECT * FROM Tasks
  6. ORDER BY ISNULL(DueDate, DATEADD(year, 10, GETDATE()))
  7.  
  8. from o in dc.Orders orderby o.DueDate ?? DateTime.Today.AddYears(10)
  9.  
  10. [Column(Storage="_DueDate", DbType="SmallDateTime")]
  11. public System.Nullable<System.DateTime> DueDate
  12. {
  13. get
  14. {
  15. if(this._DueDate == null)
  16. {
  17. return DateTime.Today.AddYears(10);
  18. }
  19. return this._DueDate;
  20. }
Add Comment
Please, Sign In to add comment