Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# LINQ
Hi,
 
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
cdpace1.5K
Rate this: bad
good
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);
}
  Permalink  
Rate this: bad
good
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.
  Permalink  
Comments
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:
http://www.west-wind.com/weblog/posts/2008/Feb/05/Linq-to-SQL-DataContext-Lifetime-Management
Parwej Ahamad at 16-Oct-12 14:07pm
   
Also look for Unito Of Work pattern:
http://drc.ideablade.com/xwiki/bin/view/Documentation/unit-of-work-pattern-and-persistence-ignorance
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 OriginalGriff 7,215
1 DamithSL 5,114
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,747
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 16 Oct 2012
Copyright © CodeProject, 1999-2014
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