gpt4 book ai didi

NHibernate:使用IList语义双向映射一对多

转载 作者:行者123 更新时间:2023-12-03 12:11:00 25 4
gpt4 key购买 nike

这是相关的部分。这是一个父对象:

public class Article
{
public virtual IList<ArticleRevision> Revisions { get; set; }
}

<list name="Revisions" cascade="all" inverse="true" table="ArticleRevision">
<cache usage="read-write" />

<key column="ArticleID" not-null="true" />
<index column="Number" type="int32" />
<one-to-many class="ArticleRevision" />
</list>

这是一个 child :
public class ArticleRevision
{
public virtual Article Article { get; set; }
}

<many-to-one name="Article" column="ArticleID" not-null="true" />

现在,我创建一个 Article实例,向 ArticleRevision集合中添加一个 Article.Revisions,设置 ArticleRevision.Article以引用 Article实例并将其推到数据库中:
INSERT 
INTO
ArticleRevision
(Content, Keywords, CreatedAt, SiteID, ArticleID, CreatedByUserID, ID)
VALUES
(@p0, @p1, @p2, @p3, @p4, @p5, @p6);

没有 Number列被插入。

如何在NHibernate中正确映射具有列表语义的双向一对多集合?

最佳答案

NHibernate documentation:

Please note that NHibernate does not support bidirectional one-to-many associations with an indexed collection (list, map or array) as the "many" end, you have to use a set or bag mapping.

关于NHibernate:使用IList语义双向映射一对多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5967843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com