We're developing an application that lets end users essentially write and execute their own Dynamics queries. Since these queries are built dynamically, we are creating them using LINQ expressions. This requires using the LINQ method syntax instead of query syntax, but most of the documentation and community examples use the query syntax. This has been fine for the simple queries we've been doing so far, but now we are trying to do multiple joins. Unfortunately, I could not find any method sytax examples for this on the internet, and I'm getting an unhelpful error that I also can not find anywhere on the internet. As an example, the following multi-join statement using the query syntax works, but the method query results in an error:var query = from a in dataContext.CreateQuery("account")
join c in dataContext.CreateQuery("contact")
on a["accountid"] equals c["parentcustomerid"]
join i in dataContext.CreateQuery("incident")
on c["contactid"] equals i["customerid"]
where i.GetAttributeValue<string>("description").StartsWith("A")
select new
{
Contact = new
{
LastName = c["lastname"]
}
};
var methodQuery = dataContext.CreateQuery("account")
.Join(dataContext.CreateQuery("contact"), a => a["accountid"], c => c["parentcustomerid"], (a, c) => new { a = a, c = c })
.Join(dataContext.CreateQuery("incident"), jt => jt.c["contactid"], i => i["customerid"], (jt, i) => new { a = jt.a, c = jt.c, i })
.Where(jt => jt.i.GetAttributeValue<string>("description").StartsWith("A"));
This is the error I get:System.InvalidOperationException : The projection property does not match an existing entity binding.
Is there some kind of limitation in the LINQ to dynamics provider that I'm missing here? Are the names and formatting wrong somehow?
Posting on another forum made me realize that I needed to add a select on the end of the method syntax query. I was trying to debug things by building up the query incrementally, but the LINQ to Dynamics provider requires that you have a select statement before a join query can be evaluated at all.
In this case, you can use early binding rather than late binding.
I know that will work, but I can't use that syntax for the work I'm doing. The LINQ method syntax is at least somewhat supported, as Microsoft has at least a few examples using it: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/org-service/linq-query-examples#use-a-method-based-linq-query-with-a-where-clause. As best I can tell, the second example is the correct way to convert the working query syntax into method syntax, but it doesn't work.
Hi,
You can use following linq:
var query = from a in dataContext.CreateQuery("account")
join c in dataContext.CreateQuery("contact")
on a["accountid"] equals c["parentcustomerid"]
join i in dataContext.CreateQuery("incident")
on c["contactid"] equals i["customerid"]
where i.GetAttributeValue<string>("description").StartsWith("A")
select new
{
Contact = new
{
LastName = c["lastname"]
}
};
Your second linq is not correct as per CRM late binding standard.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156