0

I have problem with making mapping of classes with propert of type Dictionary and value in it of type Dictionary too, like this:

  public class Class1
  {
    public virtual int Id { get; set; }

    public virtual IDictionary<DayOfWeek, IDictionary<int, decimal>> Class1Dictionary { get; set; }
  }

My mapping looks like this:

Id(i => i.Id);
HasMany(m => m.Class1Dictionary);

This doesn't work. The important thing I want have everything in one table not in two. WHet I had maked class from this second IDictionary I heve bigger problem. But first I can try like it is now.

4

1 回答 1

1

目前不可能在 NHibernate 中使用任何类型的嵌套集合。

相反,您应该如下定义您的属性:

public virtual IDictionary<DayOfWeek, Class2> Class1Dictionary { get; set; }

并添加一个新类:

public class Class2
{
    public virtual decimal this[int key]
    {
        get { return Class2Dictionary[key]; }
        set { Class2Dictionary[key] = value; }
    }

    public virtual IDictionary<int, decimal> Class2Dictionary { get; set; }
}

这样,您可以正常映射类和字典,并且仍然可以通过以下方式访问字典:

class1Instance.Class1Dictionary[DayOfWeek.Sunday][1] = 9.4
于 2010-04-10T17:45:05.113 回答