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