views:

53

answers:

1

Hello,

I'm trying to map a Dictionary containing Lists.

I have the following set of tables:

CREATE TABLE Item(id)

CREATE TABLE Filter(id)

CREATE TABLE FilterType(id)

CREATE TABLE ItemFilter(
 item REFERENCES Item(id),
 filter REFERENCES Filter(id),
 filterType REFERENCES FilterType(id)
)

and I want to do this mapping:

class Item{
 public IDictionary<long, IList<ItemFilter>> ItemFiltersByType; 
}

The long is the id of the filterType.

I was using this mapping but its not working:

Any help would be appreciated : P. Tks

+1  A: 

I don't think you can do what you're trying to do here. The closest available mapping pattern is the ternary association. This is actually what you have but you don't have a unique index. NHibernate only supports the raw IDictionary interface which does not support multiple values off a single key. If you had a unique index value for FilterType (which, judging by the name, you rightly don't), you could do:

<map name="ItemFiltersByType">
    <key column="Item_id" />
    <index-many-to-many class="FilterType" column="FilterType_id" />
    <many-to-many class="Filter" column="Filter_id" />
</map>

I think the best solution in this case would be to move the operation to a repository with a method like:

IEnumerable<Filter> GetItemFiltersByType(FilterType type);
Stuart Childs
Tks, I figured I couldn't do what I wanted after a couple of hours of searching and experimented. Ended up mapping it to a List and using Linq to group it (its a very small set of items).
Megacan