Search code examples
c#linqdynamics-crm-2011dynamics-crmdynamics-crm-online

Copying data from Linq to CRM


I'm trying to work with some data in the Dynamics Online of my client. They have some custom elements added by a third party company who aren't being at all helpful.

I need to get contacts from the standard contactSet and then grab their data from the membershipSet created by this third party org.

I'm really struggling with how to go about getting the data out of the CRM and onto the website.

from m in py3_membershipSet
join c in ContactSet on m.py3_Member.Id equals c.ContactId 
where m.statuscode.Value == 1
orderby m.py3_name
select m

This has led me to try the following on my .Net site:

var context = new XrmServiceContext();
var activeMembers = (from m in context.py3_membershipSet
join c in context.ContactSet on m.py3_Member.Id equals c.ContactId 
where m.statuscode.Value == 1
orderby m.py3_name
select m)

However, 'context' doesn't seem to contain py3_membershipSet.

What can I try next?


Solution

  • you need to generate the early bound classes (using crmsvcutil.exe) and specify the ServiceContextName parameter.

    Assuming your context is XrmServiceContext, you need to instantiate in this way:

    var context = new XrmServiceContext(service);
    

    where service is the IOrganizationService web service.