我有一个LINQ2Entity问题,我想从数据库中获取值,字符串,所以我选择FProducts.Serial_number
,为了结束查询,我做.ToDictionary
。
问题是,它告诉我它没有足够的参数来转换ToDictionary
。
所以我需要像select FProducts.Serial_number, Nothing). ToDictionary
这样的东西。
FProducts.Serial_number, 0).ToDictionary
也不起作用。
有什么建议吗?
Sub GetStatistics(ByVal ProductNumbers As List(Of String), ByRef Passed As Integer, ByRef FailedProducts As List(Of String))
Passed = 0
FailedProducts = Nothing
Dim tpDictionary As Dictionary(Of String, Integer)
For Each productNumber As String In ProductNumbers
Using context As New SelmaEntities
Dim Table = (From GoodProducts In context.TestResults
Where (GoodProducts.Art_no = productNumber)
Select GoodProducts.Art_no, GoodProducts.Failed)
tpDictionary = (From FProducts In context.TestResults
Where (FProducts.Art_no = productNumber And FProducts.Failed <> 0)
Order By FProducts.Serial_number
Select FProducts.Serial_number, ).ToDictionary
End Using
Next
End Sub
答案 0 :(得分:4)
ToDictionary
需要lambda expressions作为参数:一个用于选择字典键,一个用于选择值。所以试试:
tpDictionary = (From FProducts In context.TestResults
Where (FProducts.Art_no = productNumber And FProducts.Failed <> 0))
.ToDictionary(Function(p) FProducts.Serial_number, Function(p) 0)
答案 1 :(得分:1)
var products = from p in FProducts select new { value=serial_number,key=productid};
Dictionary<string, int> dictionary = new Dictionary<string, int>();
foreach(var item in products){
dictionary.Add(item.value, item.key);
}