FluentNHibernate mapping for Dictionary

后端 未结 3 1722
深忆病人
深忆病人 2021-01-14 06:49

What is the best way of mapping a simple Dictionary property using Fluent NHibernate?

3条回答
  •  情深已故
    2021-01-14 07:27

    Using a simple class relationship such as the following:

    public class Foo {
        public virtual IDictionary Bars { get; set; }
    }
    
    public class Bar {
        public virtual string Type { get; set; }
        public virtual int Value { get; set; }
    }
    

    You can map this with Fluent NHibernate in this way:

    mapping.HasMany(x => x.Bars)
           .AsMap(x => x.Type);
    

    Where Bar.Type is used as the key field into the dictionary.

提交回复
热议问题