【问题标题】:Get Option set label in LINQ在 LINQ 中获取选项集标签
【发布时间】:2014-09-18 18:06:36
【问题描述】:

我想知道如何在早期绑定中使用LINQ 获取CRM 2011 中选项集字段的标签。

我尝试使用FormattedValues["field_name"],但出现以下错误The given key was not present in the dictionary

var query = (from username in context.SystemUserSet 
             select new { username.FullName, 
                          Manager = (username.ParentSystemUserId == null) ? string.Empty : username.ParentSystemUserId.Name, 
                          DepartmentValue = username.new_Department, 
                          Department = username.FormattedValues["new_Department"] ,
                          username.SystemUserId });

提前致谢。

【问题讨论】:

  • 小写是否解决了您的问题?
  • 不,我仍然有同样的错误信息
  • 您是否检查过 FormattedValues 集合中有哪些字段?我只将它与查询表达式一起使用,因此您可以尝试新建一个新的 SystemUser,而不是创建一个新类型,然后查看是否可以访问其中的值。

标签: c# linq dynamics-crm-2011 crm


【解决方案1】:

您必须选择选项集字段才能访问格式化的值:

var query = (from username in context.SystemUserSet 
             select new { username.FullName, 
                          username.filed_name
                          Manager = (username.ParentSystemUserId == null) ? string.Empty : username.ParentSystemUserId.Name, 
                          DepartmentValue = username.new_Department, 
                          Department = username.FormattedValues["new_Department"] ,
                          username.SystemUserId
                          })

更新

没有看到你已经选择了它(你拼错了字段)。

始终使用小写字母。那是你的问题。

Department = username.FormattedValues["new_department"] 

【讨论】:

  • 这并不总是正确的,在创建自定义字段时,您可以在SchemaName 中使用混合大小写,而SchemaName 用于编程并且区分大小写。 LogicalName 将始终强制为小写,但 Entity() 类不会将其用于属性。这就是为什么我总是要求我的解决方案使用所有小写的 SchemaName 值,以避免任何潜在的大小写问题。
  • @Nicknow,属性集合和 FormattedValues 集合中的后期绑定实体始终使用逻辑名称,所以这就是为什么我说始终使用小写(在 C# 后期绑定中,oData 不同)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-15
  • 1970-01-01
  • 1970-01-01
  • 2016-01-24
相关资源
最近更新 更多