Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8303809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:37:49+00:00 2026-06-08T17:37:49+00:00

Hi can anyone help with a linq query, normally I populate my data grid

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:37:50+00:00Added an answer on June 8, 2026 at 5:37 pm

    I think you are looking for something like this (it isn’t the most effecient, but it should work):

    var customer = xDoc.Descendants("Customer")
            .Select(n => new
            {
                Firstname = n.Element("FirstName").Value,
                Surname = n.Element("LastName").Value,
                HireFromDate = n.Element("CustomerHireDate")
                                .Descendents("HireDate").First()
                                .Descendents("HireFromDate").First().Value,
                HireFromDate = n.Element("CustomerHireDate")
                                .Descendents("HireDate").First()
                                .Descendents("HireToDate").First().Value
            })
            .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can anyone help me write a linq query, its a bit confusing... Basically i
Can anyone help? I have a linq query which is embedded inside a extension
can anyone help?, i am stuck with a linq query.. basically i have a
Can anyone help me with a LINQ query. I have converted most of it
Can anyone help me, to convert the below sql query to Linq (Lambda Expressions).
I need to rewrite the query below using Linq to Entity. Can anyone help?
Can anyone help me to get good WordPress interview questions and answers. Any link
Can anyone help me in converting scalar type of openCV to basic types like
I am trying to send some data from a LINQ query in C# to
I'm stuggling to replicate a SQL query into LINQ. Can any one help? SQL:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.