I know Silverlight. I know data binding. I know data binding in silver light to simple object, but custom objects tend to be a bit more interesting. The problem started simple. Lets use linq to sql to return a table called assets, and bind it to a grid in Silverlight. Not so easy. Why because you cannot to my knowledge use linq to sql with silverlight. The silverlight runtime (which is a subset of the .net runtime) does not include linq to sql. Ok so lets return a list of asset objects created and transformed into a custom class from a webservice. That did not work. Here is the first article I read on my Endeavour:
http://timheuer.com/blog/archive/2008/03/14/calling-web-services-with-silverlight-2.aspx
It looks like I could return xml. This will work because silverlight supports Linq to XML. Have I mentioned my foundness of Linq ;). I should have known you cannot return a type of XDocument. I am going to return it as a string and convert it on the client.
I started reading about linq to xml here:
http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx
Side Note 1:
Now this was a horrible idea. It was recommended though. I am running with a new testing framework called Test Driven.Net. I need to detour to read about it. Here is the link.
http://www.testdriven.net/quickstart.aspx
Back on topic soon.
Here is the code so far to generate xml document from a linq to sql query
var db = new AssetDataContext();
var xml = new XElement("Assets",
from rec in db.Assets
select new XElement("Asset",
new XElement("Barcode", rec.Barcode),
new XElement("AssetNumber", rec.AssetNumber),
new XElement("BarcodeChanged", rec.BarcodeChanged),
new XElement("Comments", rec.Comments),
new XElement("CurrentStatusCode", rec.CurrentStatusCode),
new XElement("Description", rec.Description),
new XElement("EquipmentNumber", rec.EquipmentNumber),
new XElement("LastAudit", rec.LastAudit),
new XElement("LastScan", rec.LastScan),
new XElement("LastUser", rec.LastUser),
new XElement("Location", rec.Location),
new XElement("Manufacturer", rec.Manufacturer),
new XElement("Model", rec.Model),
new XElement("OldBarcode", rec.OldBarcode),
new XElement("Picture", rec.Picture),
new XElement("PlantName", rec.PlantName),
new XElement("PlantNumber", rec.PlantNumber),
new XElement("RecordFlag", rec.RecordFlag),
new XElement("RequestedStatus", rec.RequestedStatus),
new XElement("SerialNumber", rec.SerialNumber),
new XElement("Sync_Start", rec.Sync_Start)));
return xml.ToString();
I going to go ahead and post this up. I will follow it with more parts as I progress in the next couple of days.
Side Note 2:
I am done with my presentation cd so those of you who asked for a copy of the cd it will ship out tomorrow.
Code Happy
Bill Moore