c# - 在 LINQ 中获取选项集标签

标签 c# linq dynamics-crm-2011 crm

我想知道如何在早期绑定(bind)中使用 LINQCRM 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 });

提前致谢。

最佳答案

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

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"] 

关于c# - 在 LINQ 中获取选项集标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24980233/

相关文章:

c# - 使用 C# API 进行 iOS 开发

c# - C++ 到 C# 包装器空异常错误

c# - 如何将 SQL Server 表拉入内存以便对其运行查询

dynamics-crm-2011 - 使用 Dynamics CRM 中的插件设置查找字段

c# - 弃用 Dynamics CRM 中的选项列表项目

c# - 在 ASP.net MVC 中使用相同的 View 进行编辑和查看

c# - 类型化数据集中的事务

c# - 使用Linq从字典中过滤掉某些键并返回一个新字典

c# - 获取列表中每个项目的对象集合(产品)

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