【问题标题】:How to setup Fluent NHibernate Many-To-Many automapping using Set instead of Bag?如何使用 Set 而不是 Bag 设置 Fluent NHibernate 多对多自动映射?
【发布时间】:2010-03-19 19:23:21
【问题描述】:

http://www.codinginstinct.com/2010/03/nhibernate-tip-use-set-for-many-to-many.html

我想按照作者建议的方式进行流畅的 nhibernate 多对多,但使用自动映射而不是 HBM 文件。

这是我的两个实体

 public class User
    {
        public virtual int Id { get; set; }
        public virtual string Name { get; set; }
        public virtual Iesi.Collections.Generic.Set<City> Cities { get; set; }

}

 public class City{
        public virtual int Id { get; set; }
        public virtual string Name { get; set; }
        public virtual Iesi.Collections.Generic.Set<User> Users { get; set; }

}

尝试使用 HashSet、IList 和 Set。但是当我查看调用自动映射输出方法生成的 HBM 文件时:

 var autoMappings = new AutoPersistenceModel().AddEntityAssembly(entityAssembly).Where(x => x.Namespace.EndsWith("Domain"));

autoMappings.WriteMappingsTo((@"C:\TEMP");

还是包型

<bag inverse="true" name="Users" table="MNUserCity" mutable="true">
      <key>
        <column name="CityId" />
      </key>
      <many-to-many class="MyApp.Entity.Domain.User, MyApp.Entity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        <column name="UserId" />
      </many-to-many>
    </bag>

我可以在 Fluent NHibernate 中使用任何约定/覆盖来更改应用程序域中所有 ManyToMany 的集合类型吗?我查看了 IHasManyToMany 约定,但没有任何线索。

有人可以帮忙吗?谢谢。

顺便说一句,我正在使用http://github.com/jagregory/fluent-nhibernate 中的最新版本

【问题讨论】:

    标签: fluent-nhibernate


    【解决方案1】:

    UsersCities 的类型从Set 更改为ISet 应该可以解决您的问题。

    正如James 在此thread 中所述,“自动映射器非常固执且不灵活,它希望将集合公开为 IList 或 ISet。”

    【讨论】:

    • 线程链接已损坏。 @nulltoken,你有当前的吗?
    • @JamesGregory:你有备份吗?
    猜你喜欢
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    • 2011-12-15
    • 2010-12-10
    • 2011-06-28
    • 2011-01-29
    • 1970-01-01
    相关资源
    最近更新 更多