user482375
user482375

Reputation:

How to Query CRM 2011 EntityCollection in LINQ

I am trying to query a EntityCollection / PartyList using LINQs and have had no luck figuring out how to do it.

My query is:

var linqQuery = (from r in gServiceContext.CreateQuery("campaignresponse")
                 select new

                 {
                     activityid = !r.Contains("activityid") ? string.Empty : r["activityid"],
                     CustomerId = !r.Contains("customer") ? string.Empty : r["customer"]
                 });

CustomerId is the PartyList / EntityCollection. If I run that code I get, Microsoft.Xrm.Sdk.EntityCollection instead of my actual data. Any ideas on how to query the EntityCollection in LINQ and return the data? Thanks!

Upvotes: 0

Views: 6387

Answers (1)

James Wood
James Wood

Reputation: 17562

The EntityCollection has the property Entities which contains the retrieved data.

EntityCollection.Entities


Edit:

So for example:

        var result = service.RetrieveMultiple(query).Entities
            .Select(e => 
                new 
                { 
                    firstname = e.Attributes["firstname"],
                    lastname = e.Attributes["lastname"]
                });

Upvotes: 2

Related Questions