【发布时间】:2012-06-13 13:09:17
【问题描述】:
使用流畅的 nhibernate 表继承删除对象时出现异常。
我无法弄清楚我的应用程序结构和映射有什么问题,以及为什么在我使用表继承时它正在寻找多对多映射表?
添加和更新工作正常。
我没有明确设置任何映射,我使用的是默认的 fluent nhibernate 映射。
对于处理我的级联的覆盖例外,如下所示:
public class CascadeAll : IHasOneConvention, IHasManyConvention, IReferenceConvention
{
public void Apply(IOneToOneInstance instance)
{
instance.Cascade.All();
}
public void Apply(IOneToManyCollectionInstance instance)
{
instance.Cascade.All();
}
public void Apply(IManyToOneInstance instance)
{
instance.Cascade.All();
}
}
例外是:
Invalid object name 'BlogPageToPage'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'BlogPageToPage'.
我的数据库是这样的。
Page
Id (Guid)
Name
etc.
BlogPage
Page_Id (Guid, exact same as parent page)
etc.
类:
public class Page : EntityBase
{
public Page()
{
BlogPages = new List<BlogPage>();
}
public virtual IList<BlogPage> BlogPages { get; set; }
}
public class BlogPage : Page
{
public BlogPage()
{
}
public virtual IList<Post> Posts { get; set; }
}
我的删除看起来像这样:
public bool Delete(T model)
{
Session.Delete(model);
return true;
}
感谢您的意见。
【问题讨论】:
-
我知道异常是因为缺少表,我的问题更多 - 当我的继承映射应该意味着不需要时,为什么要请求该表。谢谢。
-
会不会和我数据库中的级联规则有关?
标签: c# nhibernate inheritance fluent-nhibernate