c# - MS Dynamics CRM 2011 SDK - 使用后期绑定(bind)更新实体记录

标签 c# sdk dynamics-crm-2011

有谁知道如何使用 Dynamics CRM 2011 SDK 将更改保存到后期绑定(bind)实体?

这是我试过的:

// 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!" );
}

感谢所有帮助:)

最佳答案

试试这个:

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();

关于c# - MS Dynamics CRM 2011 SDK - 使用后期绑定(bind)更新实体记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11455592/

相关文章:

c# - 如何在 C# 中访问 System.Video.FrameRate

c# - 与访客的抽象树

iphone - UITableView滚动方向

dynamics-crm-2011 - 非管理员用户是否可以为 Dynamics CRM 2011 中的现有插件注册插件步骤?

c# - 如何获取所有实体的字段 CRM 2011?

Java .vs. C# 内存使用和性能

c# - 尝试反序列化 JSON 时获取 NullReferenceException

javascript - Facebook Like 按钮动态元标签 (jQuery)

java - Android Studio 找不到 SDK

c# - 单元测试代码事件工作流