nHibernate、自动映射和链接抽象类
我在使用 nHibernate、自动映射和使用多个抽象类链的类结构时遇到一些
问题,这与此类似
public abstract class AbstractClassA {}
public abstract class AbstractClassB : AbstractClassA {}
public class ClassA : AbstractClassB {}
当我尝试构建这些映射时,收到以下错误
“FluentNHibernate.Cfg.FluentConfigurationException 未处理” 消息:创建 SessionFactory 时使用了无效或不完整的配置。检查 PotentialReasons 集合和 InnerException 了解更多详细信息。
- 数据库不是通过 Database 方法配置的。”
但是,如果我从 AbstractClassB 中删除抽象关键字,一切都会正常。只有当我在类层次结构中有多个抽象类时,才会出现此问题。
我已手动配置自动映射以包括AbstractClassA 和 AbstractClassB 都使用下面的绑定类,
public class BindItemBases : IManualBinding
{
public void Bind(FluentNHibernate.Automapping.AutoPersistenceModel model)
{
model.IncludeBase<AbstractClassA>();
model.IncludeBase<AbstractClassB>();
}
}
我不得不做一些黑客技术来解决这个问题,但是必须有更好的方法来让它工作,nHibernate 当然支持这样的东西,我只是还没有弄清楚。如何正确配置它
,
詹姆斯。
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么在 AutoMappings 中包含抽象类,它们也存在于数据库中吗?你能提供 Fluent 抛出的内部异常吗?
完成此操作后,您将尝试将 AbstractClassB 映射到数据库,这可能不是您想要的。
Why do you include abstract classes in your AutoMappings, are they presented in the database too? Could you provide the inner exception Fluent throws?
With this in place you are trying to map AbstractClassB to the database, which is supposedly not what you want.