views:

506

answers:

1

This one has me scratching my head, so I'm hoping a second pair of eyes can help me out here.

Setup:

I've got a base class called DomainEntity that all of my data transfer objects use. It basically only defines a property called Id (which is an integer).

I've got data transfer objects: Blog, Post, User DomainEntity is in the namespace Core.Domain, the data transfer objects are under Core.Domain.Model

I've got the following session builder code:

return Fluently.Configure()
    .Database(SQLiteConfiguration.Standard.UsingFile("c:\blog.db"))
    .Mappings(x => x.AutoMappings.Add(
        AutoPersistenceModel.MapEntitiesFromAssemblyOf<Blog>()
            .Where(type => 
                type.Namespace.EndsWith("Domain.Model") &&
                !type.IsAbstract &&
                type.IsClass &&
                type.GetProperty("Id") != null)    
     )).BuildSessionFactory();

When I try to test a simple query, I get an application exception on the above code (somewhere) and the error message is:

System.ApplicationException: Error while trying to build the Mapping Document for 'Core.Domain.DomainEntity' ---> NHibernate.MappingException: Could not compile the mapping document: (XmlDocument) ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.

It seems that my code/NHibernate is trying to map DomainEntity, but is failing. I thought my above code explicitly stated not to map that object by using the type.Namespace.EndsWith("Domain.Model"). Is that correct? Where am I going astray here?

Thanks for any and all help.

+1  A: 

Looks like I forgot the following line:

.WithSetup(a => a.IsBaseType = type => type == typeof(DomainEntity))

So, in its entirety, my new automapping code looks like this:

return Fluently.Configure()
                .Database(SQLiteConfiguration.Standard.UsingFile("c:\\blog.db"))
                .Mappings(x => x.AutoMappings.Add(
                   AutoPersistenceModel.MapEntitiesFromAssemblyOf<Blog>()
                       .WithSetup(a => a.IsBaseType = type => type == typeof(DomainEntity))
                       .Where(type =>
                           type.Namespace.EndsWith("Domain.Model") &&
                           !type.IsAbstract &&
                           type.IsClass &&
                           type.GetProperty("Id") != null)
                   )).BuildSessionFactory();

This seems to have cleared my error right up.

Carl