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!