Fluent nhibernate: Enum in composite key gets mapped to int when I need string
Posted
by Quintin Par
on Stack Overflow
See other posts from Stack Overflow
or by Quintin Par
Published on 2010-03-21T06:56:53Z
Indexed on
2010/03/21
7:01 UTC
Read the original article
Hit count: 683
By default the behaviour of FNH is to map enums to its string in the db.
But while mapping an enum as part of a composite key, the property gets mapped as int.
e.g.
in this case
public class Address : Entity
{
public Address() { }
public virtual AddressType Type { get; set; }
public virtual User User { get; set; }
Where AddresType is of
public enum AddressType
{
PRESENT, COMPANY, PERMANENT
}
The FNH mapping is as
mapping.CompositeId().KeyReference(x => x.User, "user_id").KeyProperty(x => x.Type);
the schema creation of this mapping results in
create table address (
Type INTEGER not null,
user_id VARCHAR(25) not null,
and the hbm as
<composite-id mapped="true" unsaved-value="undefined">
<key-property name="Type" type="Company.Core.AddressType, Company.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="Type" />
</key-property>
<key-many-to-one name="User" class="Company.Core.CompanyUser, Company.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="user_id" />
</key-many-to-one>
</composite-id>
Where the AddressType should have be generated as
type="FluentNHibernate.Mapping.GenericEnumMapper`1[[Company.Core.AddressType,
How do I instruct FNH to mappit as the default string enum generic mapper?
© Stack Overflow or respective owner