C# 4.0 正在将父实体属性值提取到子实体插件中

C# 4.0 正在将父实体属性值提取到子实体插件中,c#-4.0,microsoft-dynamics,C# 4.0,Microsoft Dynamics,如何将父实体属性值提取到创建chile entity时编写的插件中,并进行一些计算,然后再次将其分配给该父实体属性?因此,我将通过在Visual Studio中使用SDK创建插件库,在插件中这样做 第一:使用插件上下文创建组织服务 IOrganizationService service = localContext.OrganizationService; 第二:调用service.Retrieve()并传递父记录的guid Entity ent = service.Retrieve();

如何将父实体属性值提取到创建chile entity时编写的插件中,并进行一些计算,然后再次将其分配给该父实体属性?

因此,我将通过在Visual Studio中使用SDK创建插件库,在插件中这样做

第一:使用插件上下文创建组织服务

IOrganizationService service = localContext.OrganizationService;
第二:调用service.Retrieve()并传递父记录的guid

Entity ent = service.Retrieve(); //pass the guid and parent entity logical name 
第三:从检索到的实体数据中获取该值

var number = ent["attribute name you want"];
第四:做计算

number = number * 100;
第5步:调用service.Update()并将新字段的计算值传递给父记录

ent["attribute name you want"] = number;
service.Update(ent);

然后,只需将插件部署到CRM即可。

将您尝试的代码放入。。或者你的班级。。