Entity Framework – export your context as xml

Ever wanted to export your context as XML and get a representation of what is contained in it’s local view or with all linked properties even if not already loaded in your context.

  • create an entity
  • add it to the context
  • get it’s xml representation.
Author cedric = new Author() { 
                    FirstName = "Cedric", 
                    LastName = "Dumont" 
                  };
simpleContext.Authors.Add(cedric);

string s = await appContext.AsXmlAsync();

  • will result in :
<Root>
  <AUTHOR>
    <AUT_ID>1</AUT_ID>
    <AUT_FIRSTNAME>Cedric</AUT_FIRSTNAME>
    <AUT_LASTNAME>Dumont</AUT_LASTNAME>
  </AUTHOR>
</Root>
  • to do this, you will need this

PM> Install-Package CExtensions.EntityFramework -Pre

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s