开发者

nHibernate, Automapping and Chained Abstract Classes

开发者 https://www.devze.com 2022-12-25 18:33 出处:网络
I\'m having some trouble using nHibernate, automapping and a class structure using multiple chains of 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

精彩评论

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

关注公众号