Reputation: 99
I am trying to migrate a hbm.xml based nhibernate project to mapping by code. I am having problem getting the Version section working. In the hbm.xml i have:
< version name="Version" column="Version
" type="Int32" unsaved-value="0"/>
I have tried with the following mapping:
Version(x => x.Version, m =>
{
m.Column(c =>
{
c.SqlType("Int32");
c.Name("Version");
});
m.Generated(VersionGeneration.Always);
m.UnsavedValue(0);
m.Insert(true);
m.Type(new NHibernate.Type.Int32Type());
});
But nothing seems to produce the same mapping as the original hbm.xml, they all end up without the type="Int32". Has anyone got any ideas how I can do this, or if its supported in 3.2?
Cheers
Update:
See my answer
Upvotes: 1
Views: 2294
Reputation: 99
Following Toni comment I have changed my mapping to:
Version(x => x.Version, mapper =>
{
mapper.Generated(VersionGeneration.Never);
mapper.UnsavedValue(0);
mapper.Type(new NHibernate.Type.Int32Type());
});
Which prove to work as my original hbm.xml
Upvotes: 2
Reputation: 2387
If the property Version is already type of int32 then that is not inserted into the hbm file. I think the type part is only written into the xml file if the actual types are different. Example (domain entity uses int32 but we want to map it using int64):
// in the domain entity
public int RowVersion{get;set;}
// Mapping
this.Version(x => x.RowVersion, mapper =>
{
mapper.Generated(VersionGeneration.Never);
mapper.UnsavedValue(0);
mapper.Type(new NHibernate.Type.Int64Type());
});
// Xml file
<version name="RowVersion" type="Int64" unsaved-value="0" />
Upvotes: 1