MS动态CRM 2011 SDK - 使用后绑定更新实体记录(MS Dynamics CRM 20

2019-09-19 09:59发布

没有人知道如何更改保存到使用动态CRM 2011 SDK后期绑定的实体?

这是我已经试过:

// retrieve and modify a pet...
// (This part works)
Guid findId = new Guid("6CA57D73-30CC-E111-B155-00505630052F");
ColumnSet attributes = new ColumnSet(new string[] { "name", "foodtype" });

// try to retrieve
// (this also works)
pet = xrm.Retrieve("pet", findId, attributes);
if( pet!=null )
{
    Console.WriteLine( String.Format( "Retrieved pet {0} successfully!", pet["name"].ToString() ));
    // update attributes
    pet["foodtype"] = "Seaweed";
    // (from here doesn't seem to work)
    // save pet
    xrm.SaveChanges();
    Console.WriteLine( "Done!" );
}

感谢所有帮助:)

Answer 1:

尝试这个:

pet["foodtype"] = "Seaweed";

xrm.UpdateObject( pet );
xrm.SaveChanges();

编辑: "The context is not currently tracking the 'pet' entity"意味着你从获取对象Retrieve未连接到服务上下文。 有一个方法Attach ,不只是这一点。

xrm.Attach( pet );
pet["foodtype"] = "Seaweed";

xrm.UpdateObject( pet );
xrm.SaveChanges();


Answer 2:

这工作:

pet["foodtype"] = "Seaweed";
pet.EntityState = EntityState.Changed; // not sure if this is really needed
// save pet
xrm.Update(pet);


文章来源: MS Dynamics CRM 2011 SDK - Update entity record using late-binding