I need to query the entity Person
with enum property TargetBookingSystemType
public class Person : EntityWithTypedId<PersonCompositeId>
{
public virtual string Key { get; set; }
public virtual TargetBookingSystemType TargetBookingSystemType { get; set; }
}
public class PersonMap : ClassMap<Person>
{
public PersonMap()
{
this.CompositeId(x => x.Id).KeyProperty(y => y.AccountName, "[AccountName]").KeyProperty(y => y.Domain, "[Domain]");
this.Table("Person");
this.Map(x => x.Key).Column("[Key]");
this.Map(x => x.TargetBookingSystemType).Column("[TargetBookingSystemType]");//.CustomType<TargetBookingSystemType>();
}
}
public enum TargetBookingSystemType
{
GoogleCalendarAPIv3 = 1,
MSExchange2007 = 2,
MSExchange2010 = 3,
MSExchange2013 = 4,
MSOnline = 5
}
CREATE TABLE [dbo].[Person](
[Domain] [varchar](3) NOT NULL,
[AccountName] [varchar](255) NOT NULL,
[Key] [varchar](255) NOT NULL,
[TargetBookingSystemType] [nvarchar](20) NULL
)
I know that a possible solution is to change the type of the property to string but how can I achieve that using NHibernate I can have the property as an enum and still get a successful query?
Tried CustomType() but with no luck getting an error Input string was not in a correct format.
please note that the query is working when I comment out the line with mapping of TargetBookingSystemType
EDIT:
I would like to have one call to DB and after that filtering the result based on the enum. This is the method doing the query using NHibernate:
public IList<Domain.DomainObjects.Entities.Person> GetAllPersons()
{
IList<Domain.DomainObjects.Entities.Person> list = new List<Domain.DomainObjects.Entities.Person>();
string queryString = "select MR from Person MR";
return this.Session.CreateQuery(queryString).SetCacheable(true).SetCacheRegion("LongTerm").List<Domain.DomainObjects.Entities.Person>();
}
How can I get the enum property in the result aswell?