所以我有以下情况:
我有这样的词典:
Dictionary<Dictionary<string, string>, DateTime> expireDates = new Dictionary<Dictionary<string, string>, DateTime>();
其中内部字典的第一个字符串由值填充(让我们称之为articlenumber),第二个字符串由名为articleCode的值填充。总之,它们是获得我需要的首选DateTime的关键。
我尝试在WCF服务中通过Linq获取DateTime:
var cmps= dbComponents.Select(component => new WCFObjects.Contracts.Component()
{
ArticleNumber = component.ArticleNumber,
Sortiment = component.SortimentsCode,
... //irrelevant values
//PSEUDOCODE, NOT WORKING
ExpireDate = expireDates.Where(x => x.Value.Where(y => x.Key.Where(
z => z.Key == component.ArticleNumber
&& z.Value == component.SortimentsCode))).FirstOrDefault()
}).ToList();
但我正在努力创建首选的linq查询来获取key == articlenumber和value == sortimentscode的值。我尝试了一些方法,其中大多数都给了我错误
Error 'System.DateTime' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly reference?)
但是我无法弄明白,希望有人可以帮助我。
祝你好运, getoveritde
答案 0 :(得分:0)
尝试
ExpireDate = expireDates.Where(
x => x.Key.Any(
y => y.Key == component.ArticleNumber && y.Value == component.SortimentsCode)
).Select(z => z.Value).FirstOrDefault()