locked
Entity graph serialization to xml RRS feed

  • Question

  • Hi,

    I am using entity framework for our database access. I want to serialze a whole customer account with data scattered around the related tables. I want to serialze the data in XML in the right hierarchy. How can I achieve this with entity framework.

    Thanks in advance,
    navneet
    • Changed type Yichun_Feng Tuesday, September 15, 2009 2:09 AM don't follow up with necessary infomation
    • Changed type Noam Ben-Ami - MSFT1 Tuesday, September 15, 2009 5:21 PM
    Tuesday, September 8, 2009 9:45 AM

Answers

  • If the main entity got serialized, there shouldn't be any reason why related entities won't be serialized too.

    Have you verified you've loaded all related entities? either by using the Include method or by explicitly using the Load method for each reference/collection?

    Can you please show the part of the code where you load the entities ?


    Please mark posts as answers/helpful if it answers your question
    Wednesday, September 9, 2009 8:49 PM

All replies

  • You can use the Service.Runtime.Serialization.DataContractSerializer class
    Please mark posts as answers/helpful if it answers your question
    Tuesday, September 8, 2009 1:59 PM
  • Can you please provide a sample code snippet?

    Let me explain the problem in detail. I want to export whole object graph to a xml file and import data from xml to database. So my requirement is both ways. By this I will be able to import a customer account on production database and and import it into a test/dev database for reproducing customer issues.

    Any help with linked data exported/imported from/to database to/from xml will be much appriciated.
     

    Thanks,
    Navneet
    Tuesday, September 8, 2009 3:39 PM
  • All the generated entity classes in EF supports xml serialization with either XmlSerialier class or DataContractSerializer class.

    You can find information on both serializers in the MSDN / GOOGLE / BING
    Please mark posts as answers/helpful if it answers your question
    Tuesday, September 8, 2009 6:20 PM
  • I have tried both serializers to serialize the EF generated classes. It is serializing the data from that object/table only and not from the related objects/tables. I am interested in serializing complete data i.e. object graph covering all the relationships. Could you please help with this?

    A code snippet/article/blog post will really help as I am quite new to entity framework.

    thanks
    Wednesday, September 9, 2009 3:08 AM
  • If the main entity got serialized, there shouldn't be any reason why related entities won't be serialized too.

    Have you verified you've loaded all related entities? either by using the Include method or by explicitly using the Load method for each reference/collection?

    Can you please show the part of the code where you load the entities ?


    Please mark posts as answers/helpful if it answers your question
    Wednesday, September 9, 2009 8:49 PM
  • This article might help you out.  Related objects are not serialized to XML but you can sneak around the issue.

    http://thedatafarm.com/blog/data-access/xml-serializing-entity-framework-entities-with-their-children-for-soa/
    • Proposed as answer by q1w2a1s2 Thursday, February 25, 2010 5:03 PM
    Thursday, February 25, 2010 5:03 PM
  • can anybody send me the sample link plz
    Monday, April 11, 2011 7:59 PM