LINQ to CRM - OR under Where

I am trying to cite some data from Dynamics CRM 2011 using LINQ. The goal is to bring all Contact records that have changes from a specific date, or to have a child object (PERC files) from the same date. The request looks like this:

// Bring all students who have changes (at Contact entity) after specific date // momentInTime or the status of any of their perc files has been changed since // that date var students = (from c in ContactSet join pl in cga_portallogonSet on c.Id equals pl.cga_ContactId.Id join ef in cga_percfileSet on c.Id equals ef.cga_StudentId.Id where (pl.cga_PortalLogonRole.Value == 284970000) // student where (c.ModifiedOn >= momentInTime || c.CreatedOn > momentInTime) || (ef.cga_statuschangedate >= momentInTime) select c.cga_StudentNumber).Distinct().ToList(); 

The following error message will appear:

The Contact object does not contain an attribute with the name = 'cga_statuschangedate'.

I can't figure out how to do OR on two different objects. MSDN says that each entity requires a WHERE clause:

where is clause

To filter a result set where clauses can be added to one or more of> entities. Each where clause can contain only conditions related to the type of an individual object. > Invalid compound condition with multiple objects. Instead, each> object should be filtered in separate where sections.

http://msdn.microsoft.com/en-us/library/ff681565.aspx

Is there any other way to achieve what I need?

+3
source share
1 answer

Unfortunately, you cannot achieve what you want in a single linq expression, because the liunq provider uses boils before fetchXML, and fetchXML does not support the script you are using.

More ... Fetch gives you a condition inside an entity or entity-entity. These condition elements cannot have attributes in them from other related objects, only the direct parent or connected object. Here is one of many Microsoft forum posts citing this limitation of fetchXML

Probably not the answer you were looking for, huh? As an ugly alternative, you can run two separate queries and filter in memory (which can hurt performance). Or even better, if you use local deployment, you can write multiple sql for filtered views. Good luck.

+5
source

All Articles