
Hi, I have a plug-in with a LINQ query to get the parent contact of an opportunity:
var tempContact = (from c in ServiceContext.CreateQuery("contact")
where c.Id.ToString().Equals(contact_guid)
select c).FirstOrDefault();
Where "ServiceContext" is defined as:
IOrganizationService service = localContext.OrganizationService; var ServiceContext = new OrganizationServiceContext(service);
I get an error message saying that the query is incorrect. Any suggestions?
Or other query suggestions would be appreciated as well, I'm only doing this with LINQ because that's the only approach I know. I just need to get the contact associated with the opportunity, thanks.
*This post is locked for comments
I have the same question (0)Hi,
If you have the ID of the contact you can retrieve it directly instead of querying:
public void Execute(IServiceProvider serviceProvider)
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
var contact = service.Retrieve("contact", theId, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
{...}
}
Hope this helps! I'd appreciate if you'd mark this as a Verified answer.
Thanks,
Aiden