locked
What is the best way to Serialize/Deserialize EF Dbcontext or its part to XML file. RRS feed

  • Question

  • User-960309025 posted

    Dear Sirs.

    What is the best way to Serialize/Deserialize EF Dbcontext or its part to XML file. 

    Like it was in ADO.NET DataSet. You had possibility to read and write data with it's schema.

    Does this have analog in EF ?

    Thank you in Advance.

    Tuesday, October 16, 2018 4:40 PM

All replies

  • User753101303 posted

    Hi,

    It wouldn't really make sense for a DbContext (which uses an underlying connection).

    Usually you are serializing a graph of entities. The general documentation is https://docs.microsoft.com/en-us/dotnet/standard/serialization/introducing-xml-serialization but you may want to give the big picture so that we can better understand what is your real goal and see if you could have a better option.

    For example when creating/consuming web APIs serialization/deserialization can be done for you. If this is to persist data it would be best to just use a "true" database.

    Tuesday, October 16, 2018 4:52 PM
  • User1120430333 posted

    Serialize Dbcontext for what purpose to send it somewhere like a Dataset? No, Dbcontext should not be sent any where the objects on the virtual model object accessable by the Dbcontext can be serialized and sent somewhere. Better yet,  a POCO or a DTO is serialized and sent somewhere. The Dbcontext has no,  nada  and none behaviors or characteristics of an ADO.NET dataset. 

    Tuesday, October 16, 2018 4:56 PM