NHibernate mapping class properties to Rows not Co

2019-05-26 17:47发布

问题:

Is it possible to map a class with each property stored as a row in the table, not a column. The scenario is where we persist global options to the database. We store the options in an 'Options' class that has a property per option, i.e. "Expand Menu", "Save on Exit" etc.

Rather than store each option in its own table column, we would simply like to have a table with each of the class properties stored as a new row, identified by a Enum.

Is this possible?

(C# Winforms)

回答1:

Using NHibernate's EntityMode.Map might help solve this problem. It does mean that you might have to put your global options in a Dictionary collection, but you can always implement an Option class that abstracts the underlying Dictionary.

NHibernate provides the ability to map a Dictionary dynamically to a table. See NHibernate's reference on Dynamic Models