Friday, 15 March 2013

c# - How to serialize and save an object to database as Xml using Linq to SQL -


I was using the filestream to stream XML to the object and save it to disk

  Stream Str = new file stream (@ "serializedstate.xml", FileMode.OpenOrCreate) XmlSerializer x = New XmlSerializer (TypeGridState); X.Serialize (str, new gridstate {GridName = txtGridName.Text, grid column = GetGridColumnStates ()});  

This works fine and the XML file is generated on the disk. How can I use SQL as a SQL object in SQL column in SQL Server 2008 database from Linux?

to serialize in an XElement

  XmlSerializer x = new XmlSerializer (typef (gridstate)); XDocument Document = New XDocument (); (XmlWriter xw = doc.CreateWriter ()) {x.Serialize (xw, using the new gridstate {GridName = txtGridName.Text, GridColumns = GetGridColumnStates ()}); Xw.Close (); } XElement el = doc.Root;  

To use

  (XmlReader xr = el.CreateReader ()) {GridState myDeserializedObject = x.Deserialize (xr) as GridState; Xr.Close (); }  

No comments:

Post a Comment