views:

157

answers:

1

I have a scenario where I have a propertybag of key/values that would look something like:

Entry 1 : key="Load", value="2", type="int"
Entry 2 : key="DailyStatus", value="0", type="bool"

I am trying to figure out if it's possible with nhibernate to map these values to a single table that I can pull out at a later time into .net simple types.

I am trying to avoid creating classes to contain all of this data as it can be very repetitive and doesn't allow portions of the application to be as flexible as possible. I had considered storing it in XML or JSON, but this data has to be queried against on a pretty regular basis.

Has anyone mapped dictionaries of simple types to a table in nhibernate and pulled the data back out? I suppose mapping to a generic dictionary would work:

IDictionary<string, IDictionary<object, Type>>

I can do it by hand, but if there is a builtin way for nhibernate to accomplish it that would be easier.

+1  A: 

How about you create a class "Triplet" with attriutes id, key, value, type and then map it to a table called whatever you want?

epitka
that would work, but how can I tell nhibernate what the underlying type of the records are? When I access the dictionary items I want to get the simple type. Maybe using generics?I suppose this would require casting to the type value
Sean Chambers
You mean what you have in the "type" attribute of the Triplet class. Maybe you could map a Triplet class to a private field and then have a generic dictionary as public. You would populate this dictionary from the private field, using some kind of factory, or maybe just switch statement on the "type" attribute of the Tripplet. You would have to keep track of the changes so that you can push/pull entries to a private field. I am doing something simmilar, except I am serializing the whole object graph into a private field.
epitka