Поделиться через


Generate code with the code generation tool extensions (Dynamics CRM 2015)

 

Applies To: Dynamics CRM 2015

Developer Extensions for Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update provides an extension library for the CrmSvcUtil.exe code generation tool that is used to generate a data context class and data transfer objects (DTOs) for all Microsoft Dynamics CRM entities. This mechanism follows the same design pattern that SqlMetal implements in the entity framework. The data context class is responsible for all data operations and provides IQueryable interfaces for all entities in Microsoft Dynamics CRM. You can retrieve data by executing a LINQ query against the IQueryable entity set properties. You can change data by using the AddObject, DeleteObject, UpdateObject, and SaveChanges methods.

The Microsoft.Xrm.Client.CodeGeneration extension for the CrmSvcUtil.exe code generation tool provides the following capabilities:

  • Generates statically typed entity classes.

  • Generates many-to-many relationship classes.

  • Generates class names and property names based on Microsoft Dynamics CRM schema names.

  • Generates a WCF Data Services (Astoria/OData) compatible data context class for managing entities.

In This Topic

Entity classes

Data context classes

Entity classes

The entity classes generated by the code-generation tool provide the following features:

  • Support for WCF Data Services (Astoria/OData) annotation attributes.

  • Strongly typed entity attribute accessors, which provide the following:

    • Mapping of Microsoft Dynamics CRM data-types into standard CLR data-types.

    • Accessors for many-to-one relationships including:

      • Lazy loading of the related entity.

      • Accessors for the foreign key IDs.

    • Many-to-many relationship accessors, which provide lazy loading of the related entity set.

Data context classes

The data context classes generated by CrmSvcUtil.exe with the Microsoft.Xrm.Client.CodeGeneration extension use the WCF Data Services IUpdatable and IExpandProvider Interface interfaces as a consequence of inheriting the CrmOrganizationServiceContext class. For more information, see the following .NET documentation: IUpdatable Interface and IExpandProvider Interface. These interfaces include the following features:

  • Provides read, create, update, and delete operations for managing entities.

  • Provides set-link, add-link, and remove-link operations for managing relationships (1-to-N, N-to-1, and N-to-N).

  • Supports the DataServiceHostFactory for exposing Web services and REST services.

  • Provides a LINQ query provider for statically or dynamically typed queries.

  • Dynamic queries do not require code-generation

  • Handles caching in the background.

A single context class is generated to provide statically typed entity set accessors. In addition, several sub-classes are generated to provide richer portal capabilities using the query and change interceptor features of WCF Data Services.

See Also

AddObject
DeleteObject
UpdateObject
SaveChanges
Developer extensions for Microsoft Dynamics CRM 2015
Developer extensions context object model (Dynamics CRM 2015)
CrmSvcUtil.exe extension usage and command-line parameters (Dynamics CRM 2015)
Use the generated class files

© 2016 Microsoft. All rights reserved. Copyright