Hi, I'm trying to delete an entity (ForumTopic) and have that delete the Posts (ForumPost) within it. Here are my entities:
public class ForumTopic
{
public virtual int TopicID { get; set; }
public virtual IList<ForumPost> Posts { get; private set; }
...
public ForumTopic()
{
Posts = new List<ForumPost>();
}
}
public class ForumPost
{
public virtual int PostID { get; set; }
public virtual ForumTopic Topic { get; set; }
...
}
With the following mappings:
public ForumTopicMap()
{
Table("ForumTopics");
Id(x => x.TopicID);
HasMany(x => x.Posts)
.Cascade.All();
...
}
public ForumPostMap()
{
Table("ForumPosts");
Id(x => x.PostID);
References(x => x.Topic, "TopicID");
...
}
However when i delete my topic i receive the following error:
[ForumTopic.Posts#14][SQL: UPDATE ForumPosts SET TopicID = null WHERE TopicID = @p0]
This seems strange as I thought by saying Cascade.All() (I event tried Cascade.Delete()) on my HasMany mapping it would delete all the posts for this topic. I'd appreciate it if someone could show me what i'm doing wrong. Thanks