using CrmSvcUtil

Use CrmSvcUtil to generate the strongly types entity and datacontext classes

crmsvcutil

/connectionString:"Authentication Type=Integrated; Server=http://servername/orgname"

/out:"Xrm.cs" /namespace:"Xrm.solution"

/dataContextClassName:"xrm"

conntectionString–> specifies the connection string.
out –> determines the name of the .cs or .xml output file and whether there is one file or one per entity.To generate one file per entity omit .cs or .xml from the file name.
namespace –> to specify the namespace
dataContextClassName –> to specify the name of the dataContext class.

Add references to the following dlls in the project

  • System.Data.Entity, System.Data.Services, System.Data.Services.Client.
  • System.Web.Services.
  • Microsoft.Crm.Sdk, Microsoft.Crm.SdkTypeProxy.dll, Microsoft.Crm.SdkTypeProxy.XmlSerializers
  • Microsoft.Xrm.Client, Microsoft.Xrm.Portal, Microsoft.Xrm.Portal.Files

Add the generated Xrm.cs file to the project.

Add the connection string information in the config file of the application

<add name="CRMOnPremise" connectionString="Authentication Type=Integrated; Server=http://servername/orgname" />

Add following using Statements

using Xrm;
using Xrm.solution;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;

And the code for creating a new custom entity record.

            new_test testEntity1 = new new_test();
            testEntity1.new_name = "Nishant";
            testEntity1.new_lastname = "Rana";
            myXrm.AddTonew_tests(testEntity);
            myXrm.SaveChanges();

 

or could also be written as

            // create the instace of DataContext class named xrm
            var myXrm = new xrm("CRMOnPremise");
          
// use concept of Implicitly type local variable 
           
// and object intializer
            var testEntity = new new_test()
            {
                new_name = "Nishant",
                new_lastname = "Rana"
            };
            myXrm.AddTonew_tests(testEntity);
            myXrm.SaveChanges();

 
 

Similarly to update a record and delete a record we need to use

UpdateObject() and DeleteObject() function followed by call to

SaveChanges() method.

Bye.

3 thoughts on “using CrmSvcUtil

  1. So when we use the CrmSvcUtil we can get all the system and custom entities of the organization at that time.Now when any new custom entities are added we will required to generate the Class file using the CrmSvcUtil , is it right ?

  2. Very nice the way that you use the tool.
    But I have a problem: I generated a form tool to make easier the way to generate classes, but when I pass all the arguments that the tool needs, the console window gets freeze. I do not know what kind of security requeriments crmsrvcutil is using.
    But we are working in an envorioment in wich we need to generate custom entities very often. We like the tool, but what we do not like is to write a long argument string to generate our entity’s classes.

    Excuseme if my english is not good
    Greetings

  3. Pingback: LINQ to Microsoft Dynamics CRM « Nishant Rana's Weblog

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s