Avatar of teknovation
teknovation
 asked on

Sum a value in Entity Collection in C#

Can someone help me figure out how to sum the quantity value here in the EntityCollection in C#?

Thanks in advance.


  string fetchXmlResult =
                             @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' >
  <entity name='salesorder'> 
                                                 <attribute name='productid'/>
                                                <attribute name='ordernumber'/> 
                                                <attribute name='quantity'/>  
  </entity>
</fetch>";

XmlElement element1= xml.CreateElement(string.Empty, "Order", xml.DocumentElement.NamespaceURI);
           

       EntityCollection xmlResult = _crmservice.RetrieveMultiple(new FetchExpression(fetchXmlResult())); 
 foreach (Entity e in xmlResult.Entities)
                {


                    XmlElement ordernumber= xml.CreateElement("OrderNumber", xml.DocumentElement.NamespaceURI);
                    ordernumber.InnerText =  e.Attributes["ordernumber"]).ToString();
                    element1.AppendChild(ordernumber);

                    XmlElement productid= xml.CreateElement("ProductId", xml.DocumentElement.NamespaceURI);
                    productid.InnerText =  e.Attributes["productid"]).ToString();
                    element1.AppendChild(productid);
}

Open in new window

.NET ProgrammingC#

Avatar of undefined
Last Comment
Fernando Soto

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Fernando Soto

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61