我正在使用以下代码来更新实体。
Service.Update(_policy);
其中 policy 是使用 CrmSvcUtil.exe 生成的类
public partial class new_policy : Microsoft.Xrm.Sdk.Entity, System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
我使用 LINQ 检索策略,然后更新一个属性(一个 EntityReference),然后尝试更新
当此代码运行时,我收到以下错误消息:
EntityState 必须设置为 null、Created(对于 Create 消息)或 Changed(对于 Update 消息)
还有其他以我可以更新的方式生成的实体。
我试过
_policy.EntityState = EntityState.Changed
但后来我收到一条消息说
该实体是只读的,不能修改“EntityState”属性。改为使用上下文更新实体。
有谁知道是什么原因造成的?