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 PRIMA开发者_如何学GoRY 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?
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.
精彩评论