Search code examples
nhibernatenhibernate-mapping

Mapping IList items to columns


I am working with a legacy database that has a table to store up to 5 categories a user has permissions to view:

USER_ELIGIBILITY
----------------
Eligibility_Id INT PRIMARY KEY
Eligibility_Name NVARCHAR(100)
CategoryId1 INT
CategoryId2 INT
CategoryId3 INT
CategoryId4 INT
CategoryId5 INT

The following is how I have created the class:

public Eligibility : Entity
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual IList<Category> AllowedCategories { get; set; }
}

Is this the right way to model this? If so, how can I map it?


Solution

  • You can do something very similar with <dynamic-component>, only instead of IList<T> you need to map an IDictionary. See http://nhibernate.info/doc/nh/en/index.html#components-dynamic.

    Of course you can write a trivial wrapper to ignore the keys and focus only in the values from calling code.