I must convert a CRM 4 Plug-In to CRM 2011 Plug-IN. In my code a have a specific class called
TargetCreateDynamic.
create = new TargetCreateDynamic();
create.Entity = counter;
cRequest = new CreateRequest();
cRequest.Target = create;
cResponse = (CreateResponse)_cs.Execute(cRequest);
Has anybody idea which class should be this in 2011?
Use just Microsoft.Xrm.Sdk.Entity
class for CreateRequest
. Below sample code which will make you an idea how to make a plain CreateRequest in CRM 2011
internal Guid CreateEntity(IServiceProvider serviceProvider)
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService organizationService = serviceFactory.CreateOrganizationService(null);
CreateRequest createRequest = new CreateRequest();
Entity entityToCreate = new Entity("Some_Entity_LogicalName");
createRequest.Target = entityToCreate;
CreateResponse response = (CreateResponse)organizationService.Execute(createRequest);
return response.id;
}
But if I want to create new record for some entity in plug-in - I use following shorter code:
internal Guid CreateEntity(IServiceProvider serviceProvider)
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService organizationService = serviceFactory.CreateOrganizationService(null);
Entity entityToCreate = new Entity("Some_Entity_LogicalName");
return organizationService.Create(entityToCreate);
}
Please note that this is just a sample code, you do not need to create OrganizationService every time you are saving/updating/deleting some entity. You can create Organization service once for you plugin, store it in some 'global' variable and than just use it everywhere