Code Generation Using the CrmSvcUtil Tool

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Advanced Developer Extensions for Microsoft Dynamics CRM provides a command-line code generation tool called CrmSvcUtil.exe that is used to generate a data context class as well as 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 as well as to provide 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. You can find this tool in the following folder in the SDK download package:


CrmSvcUtil.exe provides the following capabilities:

  • Generates statically typed entity classes
  • Generates many-to-many relationship classes
  • Generates enumeration types for Picklist values
  • Generates class names and property names based on Microsoft Dynamics CRM display names, which are more readable than the schema names
  • Generates a WCF Data Services (Astoria/oData) compatible data context class for managing entities

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
    • Loading of the related entity as needed
    • Accessors for the foreign key IDs
    • Support for statically typed polymorphic foreign key relationships for Lookup, Customer, and Owner attribute types
  • Many-to-many relationship accessors, which provide the following:
    • Loading of the related entity as needed
    • Support for attribute change tracking
    • Update operation sends only modified attributes back to the server
    • String label accessors for Picklist attributes
    • Metadata cached for performance

Data Context Classes

The data context classes generated by the CrmSvcUtil code-generation tool use the ADO.NET Data Services IUpdatable and IExpandProvider interfaces. For more information, see the following .NET documentation: IUpdatable Interface and IExpandProvider Interface. These interfaces include the following features:

  • Read, create, update, and delete operations for managing entities.
  • Set-link, add-link, and remove-link operations for managing relationships (1-to-N, N-to-1, and N-to-N).
  • Support for the DataServiceHostFactory for exposing Web services and REST services
  • A LINQ query provider for statically or dynamically typed queries.
  • Code generation is not required for dynamic queries.
  • Caching is handled in the background.

See Also


© 2010 Microsoft Corporation. All rights reserved.