I am getting an exception when deleting an object using fluent nhibernate table inheritance.
I can’t figure out what is incorrect with my application structure and mappings, and why it is looking for a many-to-many mapping table when I am using table inheritence?
Adding and updating works fine.
I have not set any mappings explicitly, I am using the default fluent nhibernate mappings.
For the exception of an override to handle my cascades shown below:
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();
}
}
The exception is:
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'.
My database looks like this.
Page
Id (Guid)
Name
etc.
BlogPage
Page_Id (Guid, exact same as parent page)
etc.
Classes:
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; }
}
My delete looks like this:
public bool Delete(T model)
{
Session.Delete(model);
return true;
}
Thanks for your input.
Of course I am being an idiot.
The reason it is looking for that table is because I have the BlogPages as a List on the Page object which is the parent.
So when I try delete it, it simply thinks there should be another table there to match that association.
Offending line: