Fluent NHibernate: override derived classes not in the base class auto-mapping

人盡茶涼 提交于 2019-12-05 22:47:10

Your override is telling FNH that you will manually write the mappings for that class. The error you are getting is because there is nothing being mapped for Organisation (if you look at the generated HBM.xml it will be empty).

What exactly are you wanting to write the override for?

Edit:

In that case, you can do something like this:

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

And when configuring fluent nhibernate:

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

Note: This is using the latest codebase of fluent nhibernate (1.0RC).

Turned out that with latest FNH (some revision after RC) this is possible now. I wonder if this is because I asked ;-)

So I had this

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

and it stopped working after upgrading to RC. Then I moved this into its own class

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

it started to work again. Just like I wanted! Now I don't even need to indicate JoinedSubClass as this is the default, anyway. I can just override my subclass properties which is cool.

Though it wasn't too easy to figure out why NH started to complain about association of strings... I even thought that .Element is broken in RC. I wonder why JoinedSubClass still has this mapping part if it doesn't completely work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!