Matching dictionaries containing a list
I am trying to display 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;
}
long
is an identifier filterType
.
I used this mapping, but it didn't work:
Any help would be appreciated: P. Tks
a source to share
I don't think you can do what you are trying to do here. The closest display pattern available is triple association. This is actually what you have, but you don't have a unique index. NHibernate only supports the original IDictionary interface, which does not support multiple values from a single key. If you have a unique index value for the FilterType (which, as the name suggests, you rightfully don't do), you can 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 the repository using a method like:
IEnumerable<Filter> GetItemFiltersByType(FilterType type);
a source to share