Reputation: 6577
I am developing one web application using Entity framework. Before this, i had used the Dataset for data manipulation. and now i changed to entity framework 4.0. My query is that, in the Dataset version we can take the xml values by using Dataset.GetXml();
method. But i don't know how to take the same from Entity framework. If you have any idea about this, please share with me. If we can't take the same by directly, please share the code sample for taking the same.
Thanks in advance..
Upvotes: 0
Views: 1599
Reputation: 14387
Entity Framework does not have a built-in 'GetXml' function. You can however reach the same through serialization with the DataContractSerializer
. Something like this ('MyEntity'is your entity class):
using ( FileStream fs = File.OpenWrite( "Data.xml" ) )
{
XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter( fs, Encoding.UTF8 );
DataContractSerializer srlz = new DataContractSerializer( typeof( MyEntity) );
srlz.Serialize( writer, recipe );
writer.Close();
}
There are some caveats though, see this article for more info.
Upvotes: 1