locked
How to save object into DB? RRS feed

  • Question

  • I have an object. Let’s say black box. I don’t know how many nested object inside.

    Is it possible to save the object into DB and restore it late?

    Wednesday, September 29, 2010 9:26 PM

Answers

  • Hi Lucky

    I have another idea, assuming that you didn't have enougth information about the object going to be saved you can use reflection to parse its properties an also if there are properties presented as nested objects they could also be parsed for their properties using a recursive technique. you can add all of the properties pair by pair I mean FullPropertyName/PropertyValue and stock them all in a dictionary or a list and then serialize that list.

    Once you want to retirve the object, you can map all the values to the corresponding main object properties  using  the full Property  name as  identifier

    Remarque:I insist on full property name(ClassName.propertyName) because might a nested object have the same property name as its

    ancestor

     


    The complexity resides in the simplicity
    • Proposed as answer by Mike Dos Zhang Wednesday, October 6, 2010 5:50 AM
    • Marked as answer by Mike Dos Zhang Monday, October 11, 2010 11:19 AM
    Thursday, September 30, 2010 9:50 AM

All replies

  • Sure...  Look up serialization.
    Tom Shelton
    Wednesday, September 29, 2010 9:37 PM
  • Hi Lucky,

    Yes you can, there is 1001 way to do that. An idea on the fly is that you can serialize this object using binary serilization into a stream and then insert that stream as BLOB file within the data base.

     If you percise me more your request I can help you in advantage to reach your goal 


    The complexity resides in the simplicity
    Wednesday, September 29, 2010 9:38 PM

  • Yes, I looked up the serialization. It requires that each inner object should be serializable. I don’t have opportunity to make it.

    Wednesday, September 29, 2010 10:17 PM
  • Hi Lucky

    I have another idea, assuming that you didn't have enougth information about the object going to be saved you can use reflection to parse its properties an also if there are properties presented as nested objects they could also be parsed for their properties using a recursive technique. you can add all of the properties pair by pair I mean FullPropertyName/PropertyValue and stock them all in a dictionary or a list and then serialize that list.

    Once you want to retirve the object, you can map all the values to the corresponding main object properties  using  the full Property  name as  identifier

    Remarque:I insist on full property name(ClassName.propertyName) because might a nested object have the same property name as its

    ancestor

     


    The complexity resides in the simplicity
    • Proposed as answer by Mike Dos Zhang Wednesday, October 6, 2010 5:50 AM
    • Marked as answer by Mike Dos Zhang Monday, October 11, 2010 11:19 AM
    Thursday, September 30, 2010 9:50 AM
  • thanks, I'll have a look into it.
    Thursday, September 30, 2010 9:32 PM
  • Hi Lucky7777,

    Welcome to MSDN Forums!

     

    If your question has been solved, please don’t forget mark/vote the replies which helped you, this will encourage the other community members to join in discussion and help each one.

     

    Have a nice weekend!

    Mike

    *****************************************************

    [All-In-One Code Framework]

    Sample world! You will get more from this world!

    Welcome to the new world!


    Mike
    Sunday, October 3, 2010 9:20 AM