Search for equivalent Fluent Nhibernate Mapping - Mapping Map as Dictionary

谁说我不能喝 提交于 2019-12-11 06:39:55

问题


I search for a equivalent Fluent Mapping for the following Attribute-based mapping in NHibernate 2.1

[Class(typeof(Article), Table = "ARTIKEL")]
public class Article  {


  [Id(0, Name = "Id", Column = "Id")]
  public virtual int Id { get; set; }


  [Map(0)]
  [Key(1, Column = "MainArticle")]
  [IndexManyToMany(2, ClassType = typeof(Article), Column = "ChildArticle")]
  [Element(3, Column = "Amount", NotNull = true)]
  public virtual IDictionary<Article, decimal> Bundle { get; set; }


}

I am not able to get a working Fluent Mapping for NHibernate 3.0.

I ended up with

HasManyToMany<Article>().ParentKeyColumn("MainArticle").ChildKyColumn("ChildArticle").AsMap<int>("Amount");

This results in a "Illegal acces to loading collection" Exception while access the Dictionary...


回答1:


HasManyToMany(x => x.Bundle)
    .ParentKeyColumn("MainArticle")
    .ChildKyColumn("ChildArticle")
    .AsEntityMap("ChildArticle")
    .Element("Amount");



回答2:


Finaly i got a working solution:

HasMany(x => x.Bundle).Table("bundles").KeyColumn("MainArticle").AsEntityMap("ChildArticle").Element("Amount", part => part.Type<decimal>());

worked in my case.



来源:https://stackoverflow.com/questions/10191275/search-for-equivalent-fluent-nhibernate-mapping-mapping-map-as-dictionary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!