.net Microsoft.Xrm.Sdk.SaveChangesException在Dynamics CRM插件中生成
以下代码是在Microsoft Dynamics CRM插件中创建的。更新.net Microsoft.Xrm.Sdk.SaveChangesException在Dynamics CRM插件中生成,.net,dynamics-crm,xrm,.net,Dynamics Crm,Xrm,以下代码是在Microsoft Dynamics CRM插件中创建的。更新产品实体后执行代码。在产品实体中有一个名为劳动生产率的自定义字段。选择要传递给插件的所有字段: protected void ExecutePostProductUpdate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullExce
产品
实体
后执行代码。在产品
实体
中有一个名为劳动生产率
的自定义字段。选择要传递给插件的所有字段:
protected void ExecutePostProductUpdate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
IPluginExecutionContext context = localContext.PluginExecutionContext;
//Get the IOrganizationService
IOrganizationService service = localContext.OrganizationService;
//create the service context
var ServiceContext = new OrganizationServiceContext(service);
ITracingService tracingService = localContext.TracingService;
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parmameters.
Entity entity = (Entity)context.InputParameters["Target"];
// get the pre entity image
Entity preImageEntity = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.preImageAlias)) ? context.PreEntityImages[this.preImageAlias] : null;
// get the post entity image
Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;
Money price = new Money();
price = (Money)postImageEntity.Attributes["price"];
var products = from p in ServiceContext.CreateQuery("product")
select p;
foreach (var product in products)
{
Entity e = (Entity)product;
Money newPrice = new Money();
decimal labourRate = 1;
// get the preimage and postimage telephone1 value
if (preImageEntity.Attributes.Contains("new_labourrate"))
{
try
{
labourRate = (decimal)e["new_labourrate"];
}
catch
{
}
}
newPrice.Value = price.Value * labourRate;
e["price"] = newPrice;
ServiceContext.UpdateObject(e);
}
ServiceContext.SaveChanges();
}
}
上述代码导致以下错误:
未处理的异常:
System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault,
Microsoft.Xrm.Sdk,版本=5.0.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35]]:
插件(执行)出现意外异常:Plugins1.PostProductUpdate:
Microsoft.Xrm.Sdk.SaveChangesException:处理此请求时出错。
详情:
-2147220956
插件(执行)出现意外异常:Plugins1.PostProductUpdate:
Microsoft.Xrm.Sdk.SaveChangesException:处理此请求时出错。
2013-08-22T08:26:27.6655137Z
[Plugins1:Plugins1.PostProductUpdate]
[08445d1c-5e06-e311-b80b-3c4a92dbc855:后期产品更新]
您是本地还是在线?
如果您是内部部署的,请连接到Microsoft Dynamics CRM服务器上的CRM进程,并调试代码以确定引发异常的行
如果你是在线的,恐怕你只能逐行追踪
更多信息请点击这里