Hi can anyone help with a linq query, normally I populate my data grid like so from my client side for a GET request to the webservice:
{
string uri = "http://localhost:8002/Service/Customer";
XDocument xDoc = XDocument.Load(uri);
var customer = xDoc.Descendants("Customer")
.Select(n => new
{
CustomerID = n.Element("CustomerID").Value,
Firstname = n.Element("FirstName").Value,
Surname = n.Element("LastName").Value,
Age = n.Element("Age").Value,
//Time = DateTime.Parse(n.Element("TimeAdded").Value)
})
.ToList();
dataGrid1.ItemsSource = customer;
}
Which works fine but now I have linked customers to hire dates and my xml looks like so :
<ArrayOfCustomer>
<Customer>
<CustomerID>1</CustomerID>
<FirstName>G</FirstName>
<LastName>Graam</LastName>
<Age>27</Age>
<CustomerHireDate>
<HireDate>
<HireFromDate>15.07.2012</HireFromDate>
<HireToDate>29.07.2012</HireToDate>
</HireDate>
</CustomerHireDate>
</Customer>
</ArrayOfCustomer>
So far im stuck at the below method of trying to populate a datagrid with descendants of descendants:
string uriShowCarHires = "http://localhost:8002/Service/Customer/{anything}";
string Uri = uriShowCarHires.Replace("{anything}", textBox1.Text);
XDocument xDoc = XDocument.Load(Uri);
foreach (var node in xDoc.Descendants("Customer"))
{
\\..... how do you get the descendants of descendants for each n.element?
}
Im not sure if this will even populate a datagrid the way im thinking, i was hoping to avoid getting an “array” inside one of the datagrids cells. Im looking for an output abit like this:
Name etc | HireFromDate | HireToDate
G 09.12.2012 01.01.2013
If anyone could help would be grateful thanks
I think you are looking for something like this (it isn’t the most effecient, but it should work):