How do you handle the fetchxml result data?

Posted by Luke Baulch on Stack Overflow See other posts from Stack Overflow or by Luke Baulch
Published on 2009-07-31T00:17:15Z Indexed on 2010/06/01 5:23 UTC
Read the original article Hit count: 567

I have avoided working with fetchxml as I have been unsure the best way to handle the result data after calling crmService.Fetch(fetchXml). In a couple of situations, I have used an XDocument with LINQ to retrieve the data from this data structure, such as:

XDocument resultset = XDocument.Parse(_service.Fetch(fetchXml));
if (resultset.Root == null || !resultset.Root.Elements("result").Any())
{
    return;
}
foreach (var displayItem in resultset.Root.Elements("result").Select(item => item.Element(displayAttributeName)).Distinct())
{
    if (displayItem!= null && displayItem.Value != null)
    {
        dropDownList.Items.Add(displayItem.Value);    
    }
}

What is the best way to handle fetchxml result data, so that it can be easily used. Applications such as passing these records into an ASP.NET datagrid would be quite useful.

© Stack Overflow or respective owner

Related posts about Xml

Related posts about data-structures