I have an object that maintains a property bag of various properties. This is exposed through my object model as a Dictionary<string, string>
and is stored in the database as a JSON-encoded string.
What is the best way to map this class using Fluent NHibernate?
Option 1: Map to a private field, do JSON translation in my object?
Should I map the property to a private string
field, and then do serialization to/from JSON in my object itself?
Pro: NH need only know about mapping a single string to a text column which seems easy enough.
Con: My model has to track the dictionary and a string, simply to support persistence.
Option 2: Use some sort of Interceptor?
I haven't done anything with NH Interceptors before, but I know of them. Could I use an interceptor to do the Dictionary/JSON serialization, so that my model need only know about the dictionary?
Option 3: Use a different encoding strategy?
Is there a different encoding strategy, besides JSON, that NH supports natively and that I could use to serialize my dictionary?