.net - How to save a dictionary into a database with C#? -


i have been using following way save dictionaries database:

  1. convert dictionary xml.
  2. pass xml sp(stored procedure).
  3. in sp use:

    select      key1,                        value1 #temptable                                       openxml(@handle, '//valueset/values', 1)  (                                     key1 varchar(max),        value1 varchar(100)   ) 
  4. done.

is there way save dictionaries database without converting xml?

it depends whether...

  • you want data stored: fastest way (both implementation , performance) binary serialization (protocol buffers example). data not readable select , every application needs read data must use same serialization (if exists in same technology/language). point of view, breaks purpose of storing in sql database.

  • you want data readable humans: xml option while not fast , little bit difficult read , still not query-able. however, quite fast implement. can dump result file , it's still readable. moreover, can share data other applications xml widespread format.

  • you want data query-able. depending on way go, not easy implement. need 2 tables (one keys , 1 values). write either own custom mapping code map columns properties or use frameworks mapping objects tables entity framework or nhibernate.

while entity or nhibernate may appear bit huge swiss knife small problem, it's interesting built expertise in it, inner concepts re-usable , can speed development once got working setup.


Comments