Fluent NHibernate: Overriding derived classes not in automatic base class mapping

History: I had a class User and class Organization: User. I did not use any mappings for these classes, let FNH do the mapping automatically. Then i added

   public class OrganizationMap : IAutoMappingOverride<Organization>
   {
      public void Override(AutoMap<Organization> mapping)
      {
      }
   }

Please note that there are no overrides. Therefore, I did not expect any changes in the behavior of FNH. But I got this (actually when exporting the schema):

NHibernate.MappingException: (XmlDocument) (2,4): XML error checking: The 'class' element in namespace 'urn: nhibernate-mapping-2.2' has incomplete content. List of expected items: 'meta, subquery, cache, sync, comment, tuplizer, id, composite-id' in the namespace. 'Urns: NHibernate-mapping-2,2'

Orders.Core.Organization.hbm.xml :

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="">
  <class name="Orders.Core.Organization, Orders.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="Organizations" xmlns="urn:nhibernate-mapping-2.2" />
</hibernate-mapping>

, , User.hbm, - :

   public class UserMap : IAutoMappingOverride<User>
   {
      public void Override(AutoMap<User> mapping)
      {
         mapping.JoinedSubClass<Organization>("ColumnId", m => {...}
         );
      }
   }

... , , 5 Override.

?

+3
2

, FNH ( RC) . , , : -)

,

 mapping.JoinedSubClass<Organization>("UserId", m =>
    {
       m.HasMany(x => x.Currencies).Element("Currency").AsBag();
    }
 );

RC.

   public class OrganizationMap : IAutoMappingOverride<Organization>
   {
      public void Override(AutoMapping<Organization> mapping)
      {
         mapping.HasMany(x => x.Currencies).Element("Currency").AsBag();
      }
   }

. , ! , ConnectionSubClass . , .

, NH ... , .Element RC. , SessionSubClass , .

+1

FNH, . , , , ( HBM.xml, ).

?

Edit:

- :

public class MyAlteration : IAutoMappingAlteration
{
    public void Alter(AutoPersistenceModel model)
    {
        model.ForTypesThatDeriveFrom<User>(
            map => map.HasMany<User>( x => x.Children)
        );
    }       
}

nhibernate:

model.Alteration( a => a.Add<MyAlteration>());

. (1.0RC).

+1

Source: https://habr.com/ru/post/1714292/


All Articles