简体   繁体   中英

How do I update the PrimaryEntity of a CRM 2011 Workflow plugin from C#?

So, ordinarily in a CRM Plugin, I would access the primary entity by using the following code:

(Entity)context.InputParameters["Target"]

I've noticed this still works from the Create context of a Workflow; however, from the ad-hoc usage, I must use the following:

context.PreEntityImages.FirstOrDefault().Value

At any rate, once I have the Primary Entity, I run into the nasty problem where the Context does not recognize this value as being the value already in context. I have tried using an explicit Attach and UpdateObject prior to using Update, however, I receive an exception telling me this entity is already in context under a different object.

I'm sure it'll be obvious in hindsight.

Thanks in advance.

通过将每个修改后的实体设置为context.UpdateObject然后通过context.SaveChanges保存(这是来自crmsvcutil的上下文),我解决了这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM