我最近刚刚从ASP.Net 3.5升级这个项目到4.0,这样我可以使用的,因为线程安全功能的concurrentDictionary而不是字典。
要使用它,我创建使用帮助论坛中发现的代码的扩展。
现在的情况很接近的工作,我不知道我怎么可以修改扩展它才能正常工作。
下面是代码:
var catalogs = (from _catalog in entities.catalogs
from rolePermission in entities.c_roleperm
from _group in entities.c_group
from _user in entities.c_user
where _group.id == rolePermission.groupID
&& rolePermission.roleID == user.roleID
&& _catalog.groupID == rolePermission.groupID
&& _user.id == _catalog.userID
select new { name = _catalog.name, groupID = _catalog.groupID, userName = _user.name, userID = _catalog.userID, groupName = _group.name, ID = _catalog.id }
);
var listItems = catalogs.ToList(p => new CatalogItem() { name = p.name, groupID = p.groupID, userID = p.userID, username = p.userName, groupName = p.groupName, ID = p.ID }).GroupBy(p => p.groupName).ToConcurrentDictionary(p => p.Key, p => p.ToList());
而在扩展的代码:
public static class Extentions
{
public static ConcurrentDictionary<TKey, TValue> ToConcurrentDictionary<TKey, TValue>(
this IEnumerable<KeyValuePair<TKey, TValue>> source)
{
return new ConcurrentDictionary<TKey, TValue>(source);
}
public static ConcurrentDictionary<TKey, TValue> ToConcurrentDictionary<TKey, TValue>(
this IEnumerable<TValue> source, Func<TValue, TKey> keySelector)
{
return new ConcurrentDictionary<TKey, TValue>(
from v in source
select new KeyValuePair<TKey, TValue>(keySelector(v), v));
}
这是我收到的错误:
错误1无重载方法“ToConcurrentDictionary”需要两个参数
什么会我需要修改扩展到在这种情况下工作吗? 任何建议都非常赞赏。