我们能够创建没有任何问题的新实体,但是更新插件中的现有实体似乎不起作用.这适用于CRM 2011.
var crmContext = new CustomCrmContext(service);
var contact = crmContext.Contact.FirstOrDefault(c=>c.Id == targetEntity.Id);
contact.new_CustomField = "Updated";
crmContext.SaveChanges();
Run Code Online (Sandbox Code Playgroud) 我已经为我们的报价产品注册了一个插件.该插件在我们的测试环境中运行良好.我已经测试了很多次.然后在主服务器中注册该插件.但是,会出现以下情况:当我首先创建或更新报价产品时,报价产品表格会变灰:

点击报价表后,出现错误.没有可用的日志文件(如您所见).我调试了插件,但也没有错误.单击"确定"后,错误消失,所需业务发生在报价产品上(对于税收字段).意味着插件代码没有错误并且工作得很好.代码如下:
using System;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Xrm;
using System.Collections.Generic;
using Microsoft.Xrm.Sdk.Deployment;
public class Plugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
Entity entity;
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "quotedetail") { return; }
}
else
{
return;
}
try
{
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(
typeof(IOrganizationServiceFactory));
IOrganizationService service =
serviceFactory.CreateOrganizationService(context.UserId);
if (context.MessageName == "Create")
{
Entity QuoteProduct = (Entity)context.InputParameters["Target"];
Guid QPID …Run Code Online (Sandbox Code Playgroud)