1

I am trying to setup some mappings and am getting this exception:

Cannot extend unmapped class: CommonEntity

[MappingException: Cannot extend unmapped class: CommonEntity]
NHibernate.Cfg.XmlHbmBinding.ClassBinder.GetSuperclass(String extendsName) +217
NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddEntitiesMappings(HbmMapping mappingSchema, IDictionary`2 inheritedMetas) +352
NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(HbmMapping mappingSchema) +85
NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName) +156

I have 3 classes. Entity, CommonEntity and User. Theres no entity or commonentity table, only a User table. User inherits from CommonEntity and CommonEntity inherits from Entity. Entity and CommonEntity are abstract.

I have defined this mapping:

public class Mapping : ConventionModelMapper
{
    public Mapping()
    {
        IsRootEntity((type, declared) =>
        {
            return typeof(Entity<Guid>) == type.BaseType;
        });

        IsEntity((x,y) => typeof(Entity<Guid>).IsAssignableFrom(x) && !x.IsAbstract && !x.IsInterface);

        Class<Entity<Guid>>(x =>
                                {
                                    x.Id(c => c.Id, m=>m.Generator(Generators.GuidComb));
                                    x.Version(c=>c.Version, (vm) => { });
                                });
    }
}

Which is used like this:

        var types = typeof(Mapping).Assembly.GetExportedTypes().Where(t => typeof(Entity<Guid>).IsAssignableFrom(t));
        var mapping = new Mapping().CompileMappingFor(types);
        configuration.AddMapping(mapping);

Both User and CommonEntity are in the "types" array. I have tried adding a mapping for CommonEntity too but it made no difference.

        Class<CommonEntity>(x =>
        {
            x.Property(c => c.DateCreated, m => m.Type<UtcDateTimeType>());
            x.Property(c => c.DateModified, m => m.Type<UtcDateTimeType>());
        });

Also tried calling Subclass instead of Class. If i inherit User directly from Entity everything works fine. Any help?

Sam
  • 1,725
  • 1
  • 17
  • 28

1 Answers1

0

The problem appears to have been that CommonEntity was meeting the requirement for IsRootEntity. I modified it like so and things seem to be working now.

   IsRootEntity((type, declared) =>
                         {
                             return !type.IsAbstract &&
                                    new[] {typeof (Entity<Guid>), typeof (CommonEntity)}.Contains(type.BaseType);
                         });
Sam
  • 1,725
  • 1
  • 17
  • 28