R – Custom Id column in the Fluent NH entity name

automappingfluent-nhibernatenhibernates#arp-architecture

I am using S#arp architecture with Fluent Nhibernate and Automapper on a legacy DB.

The id column of one of the tables is different from the Automapping convention and therefore I tried to override it without success. I end up with this error

FluentNHibernate.Cfg.FluentConfigurationException
: An invalid or incomplete
configuration was used while creating
a SessionFactory. Check
PotentialReasons collection, and
InnerException for more detail.

  • Database was not configured
    through Database method.

FluentNHibernate.Cfg.FluentConfigurationException
: An invalid or incomplete
configuration was used while creating
a SessionFactory. Check
PotentialReasons collection, and
InnerException for more detail.

  • Database was not configured
    through Database method.

    —- NHibernate.MappingException :
    (XmlDocument)(3,6): XML validation
    error: The element 'class' in
    namespace 'urn:nhibernate-mapping-2.2'
    has invalid child element 'property'
    in namespace
    'urn:nhibernate-mapping-2.2'. List of
    possible elements expected: 'meta,
    subselect, cache, synchronize,
    comment, tuplizer, id, composite-id'
    in namespace
    'urn:nhibernate-mapping-2.2'. —-
    System.Xml.Schema.XmlSchemaValidationException
    : The element 'class' in namespace
    'urn:nhibernate-mapping-2.2' has
    invalid child element 'property' in
    namespace
    'urn:nhibernate-mapping-2.2'. List of
    possible elements expected: 'meta,
    subselect, cache, synchronize,
    comment, tuplizer, id, composite-id'
    in namespace
    'urn:nhibernate-mapping-2.2'.

How do I user the Id automapper convention and set my custom column as the id through the override functionality?

Note: This is only for one entity. I don’t want to change the general id mapping convention
Here’s my current override function

  public class AuthMap : IAutoMappingOverride<Auth>
  {
    public void Override(AutoMapping<Auth> mapping)
    {
      mapping.Table("x_auth");
      mapping.Map(x => x.Id, "user_id");
      mapping.Map(x => x.SessId, "sess_id");
    }
  }

Best Answer

Figured out:

Use it as

mapping.Id(x => x.Id).Column("user_id");