开发者

NHibernate Simple Delete Driving Me Mad

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 fo开发者_Go百科r this topic. I'd appreciate it if someone could show me what i'm doing wrong. Thanks


Try adding Inverse() to the HasMany mapping.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜