开发者

Custom Id column in the Fluent NH entity name

开发者 https://www.devze.com 2022-12-15 13:06 出处:网络
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 i

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 : IAutoMappingOverri开发者_如何学Pythonde<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");
    }
  }


Figured out:

Use it as

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号