开发者

LINQ - Putting result in a dictionary(Of String, Integer), where the integer must be 0

I have a LINQ2Entity problem, I want to get the value, string, from a database, so I select FProducts.Serial_number, and to end the query, I do .ToDictionary.

The problem is, it tells me that it doesn't have sufficient parameters, to convert ToDictionary.

So I need something like select FProducts.Serial_number, Nothing). ToDictionary. Also FProducts.Serial_number, 0).ToDictionary doesn't work.

Any recommendations?

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


ToDictionary requires lambda expressions as parameters: one to select the dictionary key, one to select the value. So try:

tpDictionary = (From FProducts In context.TestResults
                 Where (FProducts.Art_no = productNumber And FProducts.Failed <> 0))
               .ToDictionary(Function(p) FProducts.Serial_number, Function(p) 0)


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜