在LINQ中获取选项集标签

时间:2014-07-27 10:57:18

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

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

我尝试使用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 });

提前致谢。

1 个答案:

答案 0 :(得分:0)

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

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