我有一个场景,我需要List<my_custom_object>
通过基于公共列提取 anIQueryable<T>
和 a之间的匹配属性来生成一个新的Dictionary<String, String>
。
这是我的字典:
DirectoryProfilePropertiesCollection = (Dictionary<String, String>)ApiMethods.GetProfileProperties(OrganizationIdentifier, DirectoryIdentifier, DirectoryUserName, DirectoryUserPassword);
这将返回以下信息:
Key: samAccountName, Value: hgulzar
Key: sn, Value: Hassan
Key: lastname, Value: Gulzar
这里的键称为属性名称。
我也有一个IQueryable
:
var DirectoryMappingsCollection = repository.GetQuery<OrganizationDirectoryMapping>(where => where.OrganizationDirectory.Organization.OrganizationUnit.UnitIdentifier == OrganizationIdentifier && where.OrganizationDirectory.DirectoryIdentifier == DirectoryIdentifier);
该OrganizationDirectoryMapping
实体有一个名为DirectoryAttribute
当我要匹配它们时,这两个集合都有数据。的DirectoryProfilePropertiesCollection
对有AttributeName
和AttributeValue
。的DirectoryMappingsCollection
实体, OrganizationDirectoryMapping
, 具有AttributeName
和DetailName
我需要获得一个自定义类对象,它代表:DetailName
、、DirectoryAttribute
和AttributeValue
一直在尝试一些查询,但是当我遇到异常时卡住了:
Unable to create a constant value of type 'System.Collections.Generic.KeyValuePair`2'. Only primitive types or enumeration types are supported in this context.
LinQ 嵌套集合查询的问题对异常有点意义,但我仍然卡住了。
问候。
到目前为止我已经尝试过:
combinedCol = (from mapCol in DirectoryMappingsCollection
join propCol in DirectoryProfilePropertiesCollection
on mapCol.DirectoryAttribute equals propCol.Key
select new CombinedMappingDataCollection
{
DetailName = mapCol.DetailRequirement.DetailName,
AttributeName = propCol.Key,
AttributeValue = propCol.Value
}).ToList();