Click here to Skip to main content
15,882,837 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

My problem is the following. I am retrieving data from the database using Linq to sql and then binding that data to controls on my windows forms. The next part of my application I want to get the changes made to the data and serialize then to either XML or binary. Then when i load the application the second time i want to deserialize that data and commit the changes that where made in the previous "session".

I am trying to serialize my Linq to sql entities but it's no use. Maybe you guys can point me to an article or tutorial or provide some guidance as i tried many things and looking trough the internet for possible solutions and cant find anything.

Your help is greatly appreciated guys.

Thx a lot.

If you used Entity Framework, then all entity become serializable. So try serialization and De-serialization process:
SomeModel model = ...
var serializer = new XmlSerializer(typeof(SomeModel));
using (var writer = XmlWriter.Create("foo.xml"))
    serializer.Serialize(writer, model);
and to deserialize back a XML to an existing model:

var serializer = new XmlSerializer(typeof(SomeModel));
using (var reader = XmlReader.Create("foo.xml"))
    var model = (SomeModel)serializer.Deserialize(reader);
Share this answer
Yes will this keep track of the inserts and updates that have been done? Because in my i case i want to temporary save the data and then commit the changes at a later time.
Share this answer
Parwej Ahamad 16-Oct-12 14:00pm    
It's depend the how you are managing your DBContext object, fist look into this URL about the lifecycle of DBContext then you will able to implement your scenario:
Parwej Ahamad 16-Oct-12 14:07pm    
Also look for Unito Of Work pattern:
cdpace 22-Nov-12 3:28am    
Thx Parwej I appreciate your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900