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 7655185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:26:54+00:00 2026-05-31T12:26:54+00:00

I have the following code that does what I want however I was wondering

  • 0

I have the following code that does what I want however I was wondering if there was a way to do the same thing directly from a linq query.

        XElement xmlData = XElement.Parse(items.Xml);
        var itemsNotSynched =
            (from a in xmlData.Descendants(XName.Get("row", "#RowsetSchema"))
             group a by new
             {
                 employeeID = (string)a.Attribute("ows_EmployeeID"),
                 courseID = (string)a.Attribute("ows_CourseID"),
                 title = (string)a.Attribute("ows_LinkTitle")
             } into ex
             select new
             {
                 ex.Key.title,
                 ex.Key.courseID,
                 ex.Key.employeeID
             } into eb
             select eb).ToArray();

        List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
        foreach(var item in itemsNotSynched)
        {
            Dictionary<string, string> itm = new Dictionary<string, string>();
            itm.Add("employeeID", item.employeeID.ToString());
            if(item.courseID != null)
            {
                itm.Add("courseID", item.courseID.ToString());
            }
            itm.Add("title", item.title.ToString());
            list.Add(itm);
        }

Thanks in advance,

-EC-

Edit 1.

I managed to get what I wanted with using the suggestion from SLaks… I’ll give it another shot at the .Distinct()

    XElement xmlData = XElement.Parse(items.Xml);
    List<Dictionary<string,string>> itemsNotSynched =
        (from a in xmlData.Descendants(XName.Get("row", "#RowsetSchema"))
         group a by new
         {
             employeeID = (string)a.Attribute("ows_EmployeeID"),
             courseID = (string)a.Attribute("ows_CourseID"),
             title = (string)a.Attribute("ows_LinkTitle")
         } into g

         select new Dictionary<string, string>
         { 
            {"employeeID", g.Key.employeeID },
            {"courseID", g.Key.courseID },
            {"title", g.Key.title}
         } into f
         select f).ToList();
  • 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-05-31T12:26:55+00:00Added an answer on May 31, 2026 at 12:26 pm

    Using dot/fluent syntax, this is what I believe you want:

    XElement xmlData = XElement.Parse(items.Xml);
    List<Dictionary<string,string>> itemsNotSynched =
         xmlData.Descendants(XName.Get("row", "#RowsetSchema"))
         .Select(a => new
         {
             employeeID = (string)a.Attribute("ows_EmployeeID"),
             courseID = (string)a.Attribute("ows_CourseID"),
             title = (string)a.Attribute("ows_LinkTitle")
         })
         .Distinct()
         .Select(a => new Dictionary<string, string>
         { 
            {"employeeID", a.employeeID },
            {"courseID", a.courseID },
            {"title", a.title}
         })
         .ToList();
    

    Distinct() accomplishes the same thing as grouping but only using the keys. As written, this Distinct() implementation is nearly identical to what you already had, but it may perform better and/or use less memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that won't compile and although there is a way
I have the following XSLT code that almost does what I want: <xsl:variable name=scoredItems
I have following code that does not work due to a being a value
I have the following bit of legacy C++ code that does not compile: #include
I currently have code that does the following: private final static ExecutorService pool =
I have a line of PHP code that does the following: $xml = <xml><request>...[snipped
I have some code that does the following: while(some condition) { char *line[WORDLEN]; //do
I have following code snippet that i use to compile class at the run
I have the following code that shows either a bug or a misunderstanding on
I have the following code that sets a cookie: string locale = ((DropDownList)this.LoginUser.FindControl(locale)).SelectedValue; HttpCookie

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.