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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:53:20+00:00 2026-05-25T01:53:20+00:00

I am writing a prgm that via the ADO datacontext, I am running a

  • 0

I am writing a prgm that via the ADO datacontext, I am running a query on the database that uses a group clase and returns an xml document. I am able to get the xml to work, but the XAttribute("pub_id", from p in g select new { p.Pubs_id }) is giving :

System.Linq.Enumerable+WhereSelectEnumerableIterator`2[Pubs.BookStore+BookResults,<>f__AnonymousType1`1[System.String]]

below is the code:

XDocument xdoc = new XDocument(new XElement("reports",
 from b in bookResults 
 group b by b.Title1 into g 
 select new XElement("book", 
     new XAttribute("pub_id", from p in g select new { p.Pubs_id }), 
     new XElement("Title", g.Key), 
     from bk in g 
     select new XElement("Name", new XAttribute("au_id", bk.Au_id), bk.Name)) 
 ) 

xdoc.Save("Books.xml");    

sample xml output desired ( using pubs sample db)

<reports>
  <book pub_id="1389">
    <Title>The Busy Executive's Database Guide</Title>
    <Name au_id="409-56-7008">Bennet,Abraham</Name>
    <Name au_id="213-46-8915">Green,Marjorie</Name>
  </book>
  <book pub_id="0877">
    <Title>Fifty Years in Buckingham Palace Kitchens</Title>
    <Name au_id="648-92-1872">Blotchet-Halls,Reginald</Name>
  </book>
  <book pub_id="0877">
    <Title>The Gourmet Microwave</Title>
    <Name au_id="722-51-5454">DeFrance,Michel</Name>
    <Name au_id="899-46-2035">Ringer,Anne</Name>
  </book>
  • 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-25T01:53:20+00:00Added an answer on May 25, 2026 at 1:53 am

    You’re providing a query returning a sequence as the value of an attribute. My guess is that you expect there to be a single result, in which case you just need to change it to:

    new XAttribute("pub_id", (from p in g select new { p.Pubs_id }).Single())
    

    Or even:

    new XAttribute("pub_id", (from p in g select p.Pubs_id).Single())
    

    It’s not really clear whether that is what you’re expecting though – but that’s the problem. LINQ to XML is calling ToString on your query, and you’re seeing the result of that. Change the second constructor argument to something which gives a single value, however you need to do it.

    I suspect you’ll find that if you indent your code more clearly, it’ll make it more obvious what’s going on – at the moment it’s not really clear just from looking at it. I would rewrite your query as provided in the question as:

     from b in bookResults
     group b by b.Title1 into g
     select new XElement("book",
         new XAttribute("pub_id", from p in g select new { p.Pubs_id }),
         new XElement("Title", g.Key),
         from bk in g
         select new XElement("Name", new XAttribute("au_id", bk.Au_id), bk.Name))
     )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing a client application that sends images to a server via a webservice. As
Writing a sound control applet with GUI that communicates with a device via USB.
Writing a embeddable cross-browser plugin that is scriptable via JavaScript i am unsure how
Writing a Service that is running on IIS. Basically looks like this: void ProcessRequest(HttpContext
Writing a Jabber client that uses Twisted Words. I would like to know an
Writing a SQL query that should return the average charges for a preceding 91
Writing htaccess that allows me to remove index.php from the URL can confuse search
Writing documentation in html requires some code examples. What to do with characters that
Writing a recursive function, I want one fn that executes when the list has
Writing an app that will include the ability to decompress zip and rar files.

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.