开发者

How to setup Fluent NHibernate Many-To-Many automapping using Set instead of Bag?

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

I want to do the way the author suggested for fluent nhibernate many-to-many but use automapping instead of HBM file.

Here are my two entities

 public clas开发者_Go百科s 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; }

}

Tried with HashSet, IList, and Set. But when I looked at the HBM files generated by calling automapping output method:

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

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

It's still bag type

<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>

Is there any conventions/override I can use in Fluent NHibernate to alter the collection type for all the ManyToMany in the app domain? I looked at IHasManyToMany convention but no clue.

Anyone can help? Thanks.

BTW, I'm using latest build in http://github.com/jagregory/fluent-nhibernate


Changing the type of Users and Cities from Set to ISet should solve your issue.

As stated by James in this thread, "The automapper is very opinionated and inflexible, and it expects collections to be exposed as IList or ISet."

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜