For some reason in my where it says that "firstname" does not exist in the Opportunity Entity. But it is set for the SystemUser Entity. Any idea why it is getting confused? Thanks!

            var linqQuery = (from r in gServiceContext.CreateQuery("opportunity")
                             join c in gServiceContext.CreateQuery("account") on ((EntityReference)r["accountid"]).Id equals c["accountid"]
                             join u in gServiceContext.CreateQuery("systemuser") on ((EntityReference)r["ownerid"]).Id equals u["systemuserid"]
                             where r["new_leadstatus"].Equals("100000004") && u["lastname"].Equals(rsmLastName) && u["firstname"].Equals(rsmFirstName)
                             select new
                             {
                                 AccountId = !r.Contains("accountid") ? string.Empty : r["accountid"],
                                 Account = !r.Contains("name") ? string.Empty : r["name"]
                             });
link|improve this question

feedback

2 Answers

up vote 5 down vote accepted

Make sure you put each where clause in its own line per Microsoft guidelines.

The where clause applies a filter to the results, often using a Boolean expression. The filter specifies which elements to exclude from the source sequence. Each where clause can only contain conditions against a single entity type. A composite condition involving multiple entities is not valid. Instead, each entity should be filtered in separate where clauses.

var linqQuery = from r in gServiceContext.CreateQuery("opportunity")
                join c in gServiceContext.CreateQuery("account") on ((EntityReference)r["accountid"]).Id equals c["accountid"]
                join u in gServiceContext.CreateQuery("systemuser") on ((EntityReference)r["ownerid"]).Id equals u["systemuserid"]
                where r["new_leadstatus"].Equals("100000004")
                where u["lastname"].Equals(rsmLastName) && u["firstname"].Equals(rsmFirstName)
                select new
                {
                    AccountId = !r.Contains("accountid") ? string.Empty : r["accountid"],
                    Account = !r.Contains("name") ? string.Empty : r["name"]
                };
link|improve this answer
Didn't know you could have two where statements. worked like charm, thanks! – Justin 2 days ago
Learn something new everyday. Thanks @Peter – Babak Naffas 2 days ago
feedback

You define your reference to the Opportunity entity as 'r' but are trying to read firstname from 'u'

from r in gServiceContext.CreateQuery("opportunity")

u["firstname"]

Change the end of your where to

r["firstname"].Equals(rsmFirstName)
link|improve this answer
but i want to check the firstname from systemuser not opportunity and lnew_leadstatus from opportunity. – Justin 2 days ago
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.