如何在 C# 中使用 SDK 库从 Dynamics 实体中删除值
How to remove value from Dynamics Entity using SDK library in C#
我正在尝试找出如何使用控制台应用程序删除选项集属性,我最接近的是将 -1 分配给选项集值,因为当我在动态界面中执行此操作时似乎没有为该字段选择任何值。到目前为止,这是我的代码:
var employees= DataAdapter.GetEmployees(); //List of Entities
var employee1 = participants[0];
((OptionSetValue)employee1 [Constants.Attributes.GENDER]).Value = -1;
DataAdapter.UpdateParticipant(employee1);
数据适配器更新很简单:
CrmServiceClient conn = new CrmServiceClient(connectionString);
IOrganizationService _orgService;
_orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
using (OrganizationServiceContext orgSvcContext = new OrganizationServiceContext(_orgService))
{
orgSvcContext.Attach(Entity);
orgSvcContext.UpdateObject(Entity);
orgSvcContext.SaveChanges();
我正在同步来自 Dynamics 和另一个来源的数据,这就是为什么我更喜欢,例如,如果源中没有性别,如果我正在更新目标(Dynamics Solution),则不能完全具有属性而不是 -1,因为将来将 -1 与无进行比较将是不匹配的。
要显式设置没有值的性别属性,只需将 NULL 分配给该属性即可
employee1[Constants.Attributes.GENDER] = null;
我认为更好的解决方案是:
employee1.Attributes.Remove(Constants.Attributes.GENDER);
我正在尝试找出如何使用控制台应用程序删除选项集属性,我最接近的是将 -1 分配给选项集值,因为当我在动态界面中执行此操作时似乎没有为该字段选择任何值。到目前为止,这是我的代码:
var employees= DataAdapter.GetEmployees(); //List of Entities
var employee1 = participants[0];
((OptionSetValue)employee1 [Constants.Attributes.GENDER]).Value = -1;
DataAdapter.UpdateParticipant(employee1);
数据适配器更新很简单:
CrmServiceClient conn = new CrmServiceClient(connectionString);
IOrganizationService _orgService;
_orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
using (OrganizationServiceContext orgSvcContext = new OrganizationServiceContext(_orgService))
{
orgSvcContext.Attach(Entity);
orgSvcContext.UpdateObject(Entity);
orgSvcContext.SaveChanges();
我正在同步来自 Dynamics 和另一个来源的数据,这就是为什么我更喜欢,例如,如果源中没有性别,如果我正在更新目标(Dynamics Solution),则不能完全具有属性而不是 -1,因为将来将 -1 与无进行比较将是不匹配的。
要显式设置没有值的性别属性,只需将 NULL 分配给该属性即可
employee1[Constants.Attributes.GENDER] = null;
我认为更好的解决方案是:
employee1.Attributes.Remove(Constants.Attributes.GENDER);