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

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.43 KB  |  hits: 13  |  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. Add a conditional property to an FluentNHibernate ClassMap?
  2. SELECT ID, BeginDate, EndDate, CASE WHEN EndDate > GETDATE() THEN 1 ELSE 0 END AS Expired
  3. FROM myTable
  4. ORDER BY CASE WHEN EndDate > GETDATE() THEN 1 ELSE 0 END;
  5.        
  6. namespace MyDomain.Entities
  7. {
  8.     public class MyEntity
  9.     {
  10.         // [ID] [int] IDENTITY(1,1) NOT NULL
  11.         public virtual int ID { get; private set; }
  12.         // [IsDeleted] [bit] NOT NULL
  13.         public virtual bool IsDeleted { get; set; }
  14.         // [BeginDate] [datetime] NOT NULL
  15.         public virtual DateTime BeginDate { get; set; }
  16.         // [EndDate] [datetime] NOT NULL
  17.         public virtual DateTime EndDate { get; set; }
  18.     }
  19. }
  20.        
  21. namespace MyDomain.Mappings
  22. {
  23.     public class MyEntityMap : ClassMap<MyEntity>
  24.     {
  25.         public MyEntityMap ()
  26.         {
  27.             this.Table("myTable");
  28.             this.Id(x => x.ID);
  29.             this.Map(x => x.IsDeleted);
  30.             this.Map(x => x.BeginDate);
  31.             this.Map(x => x.EndDate);
  32.         }
  33.     }
  34. }
  35.        
  36. namespace MyDomain.Mappings
  37. {
  38.     public class MyEntityMap : ClassMap<MyEntity>
  39.     {
  40.         public MyEntityMap ()
  41.         {
  42.             this.Table("myTable");
  43.             this.Id(x => x.ID);
  44.             this.Map(x => x.IsDeleted);
  45.             this.Map(x => x.BeginDate);
  46.             this.Map(x => x.EndDate);
  47.             this.Map(x=>x.HasExpired)
  48.                .Formula("CASE WHEN EndDate > GetDate() THEN 1 ELSE 0 END");
  49.         }
  50.     }
  51. }