什么是targetcreateddynamic在crm 2011
本文关键字:crm 2011 targetcreateddynamic 什么 | 更新日期: 2023-09-27 17:52:14
我必须将CRM 4插件转换为CRM 2011插件。在我的代码中,我们有一个名为
的特定类TargetCreateDynamic。
create = new TargetCreateDynamic();
create.Entity = counter;
cRequest = new CreateRequest();
cRequest.Target = create;
cResponse = (CreateResponse)_cs.Execute(cRequest);
有人知道2011年哪个班应该是这个吗?
对于CreateRequest
只使用Microsoft.Xrm.Sdk.Entity
类。下面的示例代码将使您了解如何在CRM 2011中创建一个简单的CreateRequest
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;
}
但是如果我想为插件中的某些实体创建新记录-我使用以下较短的代码:
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);
}
请注意这只是一个示例代码,您不需要在每次保存/更新/删除某些实体时创建OrganizationService。你可以为你的插件创建一次组织服务,将其存储在某个"全局"变量中,然后到处使用它