Unchase Dynamics365 Connected Service is a Visual Studio 2017/2019 extension to generate early-bound .NET Framework (or C++) classes that represent the entity data model used by Dynamics 365 for Customer Engagement.
The project is developed and maintained by Nikolay Chebotov (Unchase).
Table of content
Getting Started
Install from Tools -> Extensions and Updates
menu inside Visual Studio 2017 (for VisualStudio 2019: Extensions -> Manage Extensions
) or download as VSIX
package from Visual Studio Marketplace.
Generate entity classes
The Connected Service creates a Microsoft Visual C#
or Visual Basic .NET
(or C++
) output file that contains strongly-typed classes for entities in your organization.
This includes custom entities and attributes. This output file contains one class for each entity, providing early binding and IntelliSense support in Visual Studio to aid you as you write code.
The generated classes are partial classes that can be extended with custom business logic in separate files.
You can also create extensions and use it in this tool.
For more information, see Create Extensions for the Connected Service.
Generate an OrganizationServiceContext class
The Connected Service can also be used to generate a class derived from the OrganizationServiceContext class that acts as an entity container in the entity data model.
This service context provides the facilities for tracking changes and managing identities, concurrency, and relationships.
This class also exposes a SaveChanges() method that writes inserts, updates, and deletes records in Common Data Service
.
For more information, see Use OrganizationServiceContext.
Use generated classes
The classes created by the Connected Service are designed to be built into a class library that can be referenced by projects that use Common Data Service.
After you have generated the class file using the Connected Service, you should add the file to your Visual Studio project.
You must also add references to several assemblies that the generated classes are dependent upon.
The following lists assemblies that must be referenced in your project when you use the generated code file.
Microsoft.Crm.Sdk.Proxy.dll
Microsoft.Xrm.Sdk.dll
These assemblies are part of the Microsoft.CrmSdk.CoreAssemblies NuGet package. Use this Nuget packages to add these assemblies to your Visual Studio project.
Run the Connected Service
The Connected Service takes several main parameters that determine the contents of the file that is created:
Generating Language
option - the language to generate the code in. C# or Visual Basic or C++
Service name
- the name of the folder (after generation) in Connected Service directory in the project (by default, if field is empty — Dynamics365Service)
Dynamics 365 service URI
- The URI for the Organization service endpoint (URL or local file)
Additional Generation Options
Also there are several additional options:
Namespace
- the namespace for the generated code. The default namespace is the global namespace
Generated code file name prefix
- the file name prefix for the generated code ('Generated' will be added after this)
Service Context Name
- the name for the generated service context class. If a value is passed in, it will be used for the Service Context. If no value is supplied, no service context is created)
Generate messages
checkbox - generate messages
Message Namespace
- namespace of messages to generate
Generate wrapper classes for custom actions
checkbox - generate request and response classes for custom actions
Enable Generation Tracing
checkbox - it is may take much more additional minutes. It is recommended to use when errors occur
Add client NuGet-package before generation
checkbox - allows automatically add Microsoft.CrmSdk.CoreAssemblies NuGet package to the client project
Open generated files on complete in IDE
checkbox - allows automatically open the generated files in IDE after generation process
Connecting to the CRM
There are several ways to connect to the CRM:
Interactive Login
- when used, a dialog to log into the Common Data Service service is displayed. All other connection related parameters specified on the Connected Service options are ignored:
Connection String
- contains information, provided as a single string, for connecting to a Common Data Service organization. All other connection related parameters specified on the Connected Service options are ignored:
For more information see Use connection strings in XRM tooling to connect to Common Data Service.
Create Extensions for the Connected Service
Create a .NET Framework 4.7.2 library project
Add Unchase.Dynamics365.Customization NuGet package to your project
Add a custom public class that implements one of interfaces from NuGet package :
ICustomizeCodeDomService
- called after the CodeDOM generation has been completed, assuming the default instance of ICodeGenerationService
. It is useful for generating additional classes, such as the constants in picklists
ICodeWriterFilterService
- called during the process of CodeDOM generation, assuming the default instance of ICodeGenerationService
, to determine whether a specific object or property should be generated
ICodeWriterMessageFilterService
- called during the process of CodeDOM generation, assuming the default instance of ICodeGenerationService
, to determine whether a specific message should be generated. This should not be used for requests/responses as these are already generated in Microsoft.Crm.Sdk.Proxy.dll and Microsoft.Xrm.Sdk.dll
IMetadataProviderService
- called to retrieve the metadata from the server. This may be called multiple times during the generation process, so the data should be cached
IMetaDataProviderQueryService
ICodeGenerationService
- core implementation of the CodeDOM generation. If this is changed, the other extensions may not behave in the manner described
INamingService
- called during the CodeDOM generation to determine the name for objects, assuming the default implementation
- The following sample code demonstrates how to write an extension:
using System;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk.Metadata;
using Unchase.Dynamics365.Customization;
namespace TestDynamics
{
/// <summary>
/// Sample extension for the "Unchase Dynamics365 Connected Service" that generates early-bound
/// classes for custom entities.
/// </summary>
public sealed class BasicFilteringService : ICodeWriterFilterService
{
public BasicFilteringService(ICodeWriterFilterService defaultService)
{
this.DefaultService = defaultService;
}
private ICodeWriterFilterService DefaultService { get; set; }
public async Task<bool> GenerateAttributeAsync(AttributeMetadata attributeMetadata, IServiceProvider services)
{
return await this.DefaultService.GenerateAttributeAsync(attributeMetadata, services);
}
public async Task<bool> GenerateEntityAsync(EntityMetadata entityMetadata, IServiceProvider services)
{
if (!entityMetadata.IsCustomEntity.GetValueOrDefault()) { return false; }
return await this.DefaultService.GenerateEntityAsync(entityMetadata, services);
}
public async Task<bool> GenerateOptionAsync(OptionMetadata optionMetadata, IServiceProvider services)
{
return await this.DefaultService.GenerateOptionAsync(optionMetadata, services);
}
public async Task<bool> GenerateOptionSetAsync(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
{
return await this.DefaultService.GenerateOptionSetAsync(optionSetMetadata, services);
}
public async Task<bool> GenerateRelationshipAsync(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata, IServiceProvider services)
{
return await this.DefaultService.GenerateRelationshipAsync(relationshipMetadata, otherEntityMetadata, services);
}
public async Task<bool> GenerateServiceContextAsync(IServiceProvider services)
{
return await this.DefaultService.GenerateServiceContextAsync(services);
}
}
}
Build the project so that the output dll file is created
Browse
created dll file with one or all classes that implements interfaces to add them into generation process:
HowTos
Installation completes but I can't see the Service in the list of connected services (Visual Studio 2019)
Roadmap
See the changelog for the further development plans and version history.
Thank me!
If you like what I am doing and you would like to thank me, please consider:
Thank you for your support!
Copyright © 2019 Nikolay Chebotov (Unchase) - Provided under the Apache License 2.0.