
Untitled
By: a guest on
May 2nd, 2012 | syntax:
None | size: 1.43 KB | hits: 13 | expires: Never
Add a conditional property to an FluentNHibernate ClassMap?
SELECT ID, BeginDate, EndDate, CASE WHEN EndDate > GETDATE() THEN 1 ELSE 0 END AS Expired
FROM myTable
ORDER BY CASE WHEN EndDate > GETDATE() THEN 1 ELSE 0 END;
namespace MyDomain.Entities
{
public class MyEntity
{
// [ID] [int] IDENTITY(1,1) NOT NULL
public virtual int ID { get; private set; }
// [IsDeleted] [bit] NOT NULL
public virtual bool IsDeleted { get; set; }
// [BeginDate] [datetime] NOT NULL
public virtual DateTime BeginDate { get; set; }
// [EndDate] [datetime] NOT NULL
public virtual DateTime EndDate { get; set; }
}
}
namespace MyDomain.Mappings
{
public class MyEntityMap : ClassMap<MyEntity>
{
public MyEntityMap ()
{
this.Table("myTable");
this.Id(x => x.ID);
this.Map(x => x.IsDeleted);
this.Map(x => x.BeginDate);
this.Map(x => x.EndDate);
}
}
}
namespace MyDomain.Mappings
{
public class MyEntityMap : ClassMap<MyEntity>
{
public MyEntityMap ()
{
this.Table("myTable");
this.Id(x => x.ID);
this.Map(x => x.IsDeleted);
this.Map(x => x.BeginDate);
this.Map(x => x.EndDate);
this.Map(x=>x.HasExpired)
.Formula("CASE WHEN EndDate > GetDate() THEN 1 ELSE 0 END");
}
}
}