我在NHibernate 2.1中搜索以下基于属性的映射的等效Fluent Mapping
[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; }
}
我无法为NHibernate 3.0获得有效的Fluent Mapping。
我最终得到了
HasManyToMany<Article>().ParentKeyColumn("MainArticle").ChildKyColumn("ChildArticle").AsMap<int>("Amount");
这会在访问Dictionary ...
时导致“非法访问加载集合”异常答案 0 :(得分:0)
HasManyToMany(x => x.Bundle)
.ParentKeyColumn("MainArticle")
.ChildKyColumn("ChildArticle")
.AsEntityMap("ChildArticle")
.Element("Amount");
答案 1 :(得分:0)
最终,我得到了一个有效的解决方案:
HasMany(x => x.Bundle).Table("bundles").KeyColumn("MainArticle").AsEntityMap("ChildArticle").Element("Amount", part => part.Type<decimal>());
在我的案例中工作。