Hello,

Using Fluent NHibernate, how do I specify the *Custom SQL Type* which
my *Identity
*properties will be mapped to?

Specifically, I want all Int32 fields to be mapped to MEDIUMINT (3 bytes)
within MySQL. Referring to the code below, I want PersonId to be of type
MEDIUMINT in the database.

*Entity Definition*:

    public class Person
    {
        public virtual int PersonId { get; set; }
        public virtual string FullName { get; set; }
        public virtual int Age { get; set; }
    }

*Mapping Class*:

    public class PersonMap : ClassMap<Person>
    {
        public PersonMap()
        {
            Id(i => i.PersonId).GeneratedBy.Identity();
            Map(i => i.FullName);
            Map(i => i.Age).CustomSqlType("mediumint");
        }
    }

*Generated HBM File*:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
default-access="property" auto-import="true" default-cascade="none"
default-lazy="true">
  <class xmlns="urn:nhibernate-mapping-2.2"
name="netquepgcurrent.Entities.Person, netquepgcurrent, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null" table="`Person`">
    <id name="PersonId" type="System.Int32, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="PersonId" />
      <generator class="identity" />
    </id>
    <property name="FullName" type="System.String, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="FullName" />
    </property>
    <property name="Age" type="System.Int32, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Age" sql-type="mediumint" />
    </property>
  </class>
</hibernate-mapping>

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibern...@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to