I need to fetch all related quote products under the quote entity. I used a query expression for this to retrieve the corresponding Total amount for each product. Now I need to sum the total amounts. My code is not working, the field I’m retrieving is a money/currency field.
My code goes like this:
Guid RecordGuid = entity.GetAttributeValue<Guid>("quoteid");
QueryExpression query = new QueryExpression("quotedetail");
query.ColumnSet = new ColumnSet(new string[] { "nexus_marginalamount", "baseamount"});
query.Criteria.AddCondition("quoteid", ConditionOperator.Equal, RecordGuid);
query.PageInfo.ReturnTotalRecordCount = true;
EntityCollection result = service.RetrieveMultiple(query);
Money m = new Money ();
foreach (Entity EntityResult in result.Entities)
{
m = m + EntityResult.GetAttributeValue<Money>("nexus_marginalamount");
}
entity["nexus_marginalamount"] = new Money(m.Value);