0

Ok, firstly I hope this makes sense.

I'm trying to use fluent auto mappings for my app based around the following idea.

public abstract class Container
{
  public virtual int Id {get; set};
  public virtual string Name {get; set;}
}

public class FirstSubClass : Container
{
   //properties and behaviour here
}

public class SecondSubClass : Container
{
  //properties of SecondSubclass Here
}

public class ProcessStep
{
   public virtual Container Source {get; set}
   public virtual Container Destination {get; set;}
}

However, when I try to generate the schema or test my mappings (with SQLite or otherwise) it's failing noting :

NHibernate.MappingException : An association from the table ProcessStep refers to an unmapped class: ......Entities.Container

If I change the Container class and make it none abstract it works.

Can I expose a property on an entity against a base type, with the base remaining abstract?

Any help would be gratefully appreciated.

Tim Butterfield
  • 565
  • 5
  • 24

1 Answers1

4

By default Fluent Nhibernate ignores abstract base classes when generating mappings. To include it you need to use IncludeBase method:

AutoMap.AssemblyOf<Container>(cfg)
       .IncludeBase<Container>();
Sly
  • 15,046
  • 12
  • 60
  • 89
  • Thanks @Sly. I've actually moved on since posing the question and wondered whether I can change from a abstract base to an interface. So where I've referenced Container, replace with IContainer? Is this possible as ProcessStep can't maintain any given Key Constraint. Can I then generate the schema without generating a constraint, and allowing for nulls? – Tim Butterfield Apr 08 '11 at 15:52