You can't perform operations on the left hand side of a CRM LINQ Query predicate; which is what the following is attempting to do:
((EntityReference)r["ownerid"]).Name.Equals(rsmName)
Each CRM LINQ Query predicate (where sub-clause) must have the following format:
- Left hand side is a CRM attribute
- Valid operator between LHS and RHS
- Right hand side is a variable or literal
In order to "test" the Name of the Owner in this query, you will need to join the opportunity to systemuser via the ownerid attribute:
var linqQuery = (from r in gServiceContext.CreateQuery("opportunity")
join c in gServiceContext.CreateQuery("account") on ((EntityReference)r["accountid"]).Id equals c["accountid"] into opp
join u in gServiceContext.CreateQuery("systemuser") on ((EntityReference)r["ownerid"]).Id equals u["systemuserid"]
from o in opp.DefaultIfEmpty()
where u["name"].Equals(rsmName)
select new
{
AccountId = !r.Contains("accountid") ? string.Empty : r["accountid"],
Account = !o.Contains("name") ? string.Empty : o["name"]
});
--pogo (pat) @ pogo69.wordpress.com