Introduction
The Linq to Fetch project provides a custom query provider for Microsoft Common Data Service/Dynamics 365.
Usage
You can download the binaries from nuget here, or run from package manager console
Install-Package Chorus.LinqToXrm
If you would want to use it from a sandbox plugin, make sure to add our Publicize.Fody version to your plugin project.
IOrganizationService svc = {organization service here};
var ctx = new XrmQueryProvider(svc);
var q = from contact in ctx.CreateQuery<Contact>()
where contact.FullName.Contains("test")
select contact.FullName;
Using FetchConditionOperator
IOrganizationService svc = {organization service here};
var ctx = new XrmQueryProvider(svc);
var q = ctx.CreateQuery<Contact>()
.Where(c => c.BirthDate.Is(FetchConditionOperator.LastXYears, 5));
Using web-api
Install-Package Chorus.LinqToXrm.Async
var ctx = new AsyncFetchQueryProvider(new XrmAsyncFetchService("{url}", null, "{client_id}", "{redirect_url}"));
var q = await provider.CreateQuery<contact>()
.AsAsyncEnumerable()
.ToArray();
Features
- Where-clauses of some complexity (And/Or, greater/less-than etc.)
- Inner and Outer Joins through relationships, including many-to-many ones.
- Translation of queries to FetchXML
- Parsing of result to anonymous types or CRM entities
- Orderby even for attributes selected by a joined entity.
- Skip/Take
- Count
- Contains, StartsWith, EndsWith
- Constant in a where clause can be both on the right and the left side.
- Contains translates to the IN FetchXML operator on collection objects.
-
Multi-Select Picklist conditions.
Has
andDoesNotHave
extensions methods translates tocontain-values
andnot-contain-values
conditions. -
Under and NotUnder conditions. The
Is<T>
extension method accepts anyFetchConditionOperator
. - All FetchXml conditions are now supported.