views:

89

answers:

1

Hello,

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.

+1  A: 

It's not currently possible to use nested collections of any type in NHibernate.

Instead, you should define your property as follows:

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

And add a new class:

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; }
}

This way, you can map both classes and dictionaries normally, and still access your dictionary as:

class1Instance.Class1Dictionary[DayOfWeek.Sunday][1] = 9.4
Diego Mijelshon
Ok,but when I make like this I still have problem with mapping can You write how in right way map this?
JS Future Software
I don't use Fluent. With hbm, it's a simple <map>, read http://knol.google.com/k/fabio-maulo/nhibernate-chapter-6/1nr4enxv3dpeq/9. I don't know what the FNH equivalent is.
Diego Mijelshon
I have tried Your solution but now I don't now how map this even in hbm. Can You help me ?
JS Future Software
Ok, I have made this :) If someone want solution only ask ;)
JS Future Software

related questions