views:

15

answers:

1

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?

+1  A: 

You can do something very similar with <dynamic-component>, only instead of IList<T> you need to map an IDictionary. See http://nhforge.org/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.

Diego Mijelshon
See also: http://ayende.com/Blog/archive/2009/04/11/nhibernate-mapping-ltdynamic-componentgt.aspx
Jamie Ide