Search code examples
nhibernateinheritancefluent-nhibernatesharp-architecture

Ignore Base class with Sharp Architecture and Fluent NHibernate


Using Sharp Architecture 1.9

I have a base class that inherits from the Sharp Arch Entity class

public class LineItem : EntityWithTypedId<Guid>
{
  // various properties
}

and then two classes that inherit:

public class BasketItem : LineItem { public virtual Basket Basket; ...}
public class OrderItem : LineItem { public virtual Order Order ...}

In my database I have two tables. BasketItems and OrderItems.

My problem: Fluent NHibernate (AutoMapping) is trying to map LineItem.

My question: How do I tell NHibernate to ignore the LineItem mapping given that I still want to map the EntityWithTypedId property to the BasketItems and OrderItems table?


Solution

  • The solution was to add code like this to my automap configuration:

    AutoMap.AssemblyOf<Entity>(cfg)
      .IgnoreBase<Entity>();
    

    More info here.