Chorus.LinqToXrm

A LINQ to FetchXML query provider which supports many scenarios unsupported by the Dynamics SDK's implementation.


Keywords
FetchXml, linq, CDS, XRM, Dynamics, 365, CRM
License
MS-PL
Install
Install-Package Chorus.LinqToXrm -Version 1.1.32

Documentation

Build status NuGet Status

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 NuGet Status
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 and DoesNotHave extensions methods translates to contain-values and not-contain-values conditions.
  • Under and NotUnder conditions. The Is<T> extension method accepts any FetchConditionOperator.
  • All FetchXml conditions are now supported.