Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# LINQ
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.
Posted 16-Oct-12 8:13am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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);
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.
Parwej Ahamad at 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 at 16-Oct-12 14:07pm
Also look for Unito Of Work pattern:
cdpace at 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)

  Print Answers RSS
0 Peter Leow 295
1 Mika Wendelius 275
2 CHill60 190
3 TheRealSteveJudge 190
4 Rob Philpott 130
0 Sergey Alexandrovich Kryukov 8,613
1 OriginalGriff 6,581
2 Peter Leow 3,962
3 Zoltán Zörgő 3,480
4 Richard MacCutchan 2,502

Advertise | Privacy | Mobile
Web03 | 2.8.150123.1 | Last Updated 16 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100