I’ve just released version 2.3 of the Data8 Dataverse client library, which you can use to connect to on-premise instances of Dynamics CRM / Dynamics 365 from .NET Core apps.

In this release I’ve added support for early-bound classes and async method.

Early bound support

It’s all still built on the same classes as the standard Microsoft library, so your early-bound classes generated with CrmSvcUtil or the Early Bound Generator tool will continue to work. Just pass in the OnPremiseClient instance to the early bound context instead of the normal ServiceClient instance.

var client = new OnPremiseClient(url, username, password);
client.EnableProxyTypes();

var context = new CrmServiceContext(client);
var newContacts = context.ContactSet
  .Where(c => c.CreatedOn > DateTime.Today)
  .Select(c => new { c.FirstName, c.LastName })
  .ToList();

All the normal strongly-typed goodness of your early bound classes will continue to work, translating Linq queries to FetchXML and letting you add, update and delete records easily.

Note the call to the EnableProxyTypes method before creating the context – similar to the old CrmServiceClient, this call is required to register the early bound types ready for use. If you miss this call you’ll get errors like:

Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'contact'

Async support

The OnPremiseClient class now implements the IOrganizationServiceAsync and IOrganizationServiceAsync2 interfaces, so you can use standard async programming models:

var client = new OnPremiseClient(url, username, password);
var contact = new Entity("contact")
{
  ["firstname"] = "Mark",
  ["lastname"] = "Carrington"
};
contact.Id = await client.CreateAsync(contact);

Hopefully this will help make it easier to transition more legacy applications integrating with on-premise Dynamics to .NET Core and beyond!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.