开发者

nHibernate, Automapping and Chained Abstract Classes

I'm having some trouble using nHibernate, automapping and a class structure using multiple chains of abstract classes

It's something akin to this

public abstract class AbstractClassA {}

public abstract class AbstractClassB : AbstractClassA {}

public class ClassA : AbstractClassB {}

When I attempt to build these mappings, I receive the following error

"FluentNHibernate.Cfg.FluentConfigurationException was unhandled Message: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

  • Database was not configured through Database method."

However, if I remove the abstract keyword from AbstractClassB, everything works fine. The problem only occurs when I have more than one abstract class in the class hierarchy.

I've manually configured the automapping to include both AbstractClassA and AbstractClassB using the following binding class

开发者_StackOverflow社区public class BindItemBases : IManualBinding
{
    public void Bind(FluentNHibernate.Automapping.AutoPersistenceModel model)
    {
        model.IncludeBase<AbstractClassA>();
        model.IncludeBase<AbstractClassB>();
    }
}

I've had to do a bit of hackery to get around this, but there must be a better way to get this working. Surely nHibernate supports something like this, I just haven't figured out how to configure it right.

Cheers,

James


Why do you include abstract classes in your AutoMappings, are they presented in the database too? Could you provide the inner exception Fluent throws?

model.IncludeBase<AbstractClassA>();
model.IncludeBase<AbstractClassB>();

With this in place you are trying to map AbstractClassB to the database, which is supposedly not what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜