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

  • Home
  • SEARCH
  • 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 7161815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:37:51+00:00 2026-05-28T13:37:51+00:00

I am using Linq To Xml to create an Xml file from DataSet. This

  • 0

I am using Linq To Xml to create an Xml file from DataSet. This dataset is having Customer, Orders table with 1:M relations.

Here is my code snippet –
If any of the current customer order is of type ‘Online’ then I am trying to add several attributes to XElement ‘OnlineOrder’. Otherwise if there is no order with ‘Online’ type then I want to create an empty XElement like <OnlineOrder/>.

    new XElement("OnlineOrder", ((customerDT.FindByCustomerId(x.CustomerId).GetOrdersRows().Where(o=>o.Type=="Online").Any())
            ? customerDT.FindByCustomerId(x.CustomerId).GetOrdersRows().Where(p1 => p1.Type == "Online").Select(
                (o1 => new XAttribute("Amount", o1.Amount)//,
                        //new XAttribute("CardType", o1.CardType),
                        //new XAttribute("Quantity", o1.Quantity)
                ))
            : null)),

Above code is working fine.

But if I uncomment two lines where I am adding some extra attribute, I get several compile error with one of them being –

Invalid expression term ':'

Please guide why this is happening.

Thank you!

  • 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-28T13:37:52+00:00Added an answer on May 28, 2026 at 1:37 pm

    You need to supply a list of attributes …

    new XElement("OnlineOrder", ((customerDT.FindByCustomerId(x.CustomerId).GetOrdersRows().Where(o=>o.Type=="Online").Any())
            ? customerDT.FindByCustomerId(x.CustomerId).GetOrdersRows().Where(p1 => p1.Type == "Online").Select(
                (o1 => new List<XAttribute>() { new XAttribute("Amount", o1.Amount),
                        new XAttribute("CardType", o1.CardType),
                        new XAttribute("Quantity", o1.Quantity) }
                ))
            : null)),
    

    By the way, your code would be much easier to follow / debug if it were not so dense. Why not break it up into methods, or use local variables?

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

Sidebar

Related Questions

I am trying to extract values from an XML file using linq to create
using LINQ to XML, this is a sample of my XML <shows> <Show Code=456
I'm using Linq to XML to create a new XML file. Some part of
I need to create application log file using Linq-To-Xml. I would like to lock
I have an xml file from which I am extracting html using LINQ to
I'm trying to create an XML file using C# and Linq to XML, but
I'm using Linq-to-XML to do a simple is this user registered check (no security
How to write binary data into XML using LINQ which is being read from
When reading a XML file with linq to XML using a XDocument and there
I have this XML file that I parse into its elements and create a

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.