使用流畅的nhibernate表继承删除对象时出现异常

时间:2012-06-13 03:42:51

标签: c# nhibernate inheritance fluent-nhibernate

使用流畅的nhibernate表继承删除对象时出现异常。

我无法弄清楚我的应用程序结构和映射有什么不正确,以及当我使用表继承时它为什么要查找多对多映射表?

添加和更新工作正常。

我没有明确设置任何映射,我使用的是默认的流畅的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;
    }

感谢您的意见。

2 个答案:

答案 0 :(得分:0)

“BlogPageToPage”与您的任何数据库或表名或列名都不匹配...您能找到您提到“BlogPageToPage”对象的位置吗?

答案 1 :(得分:0)

当然我是个白痴。

它寻找该表的原因是因为我将BlogPages作为父对象的Page对象上的List。

因此,当我尝试删除它时,它只是认为应该有另一个表来匹配该关联。

违规行:

    public virtual IList<BlogPage> BlogPages { get; set; }