Error Type Expected on LINQ Query

PhilippeRenaud
PhilippeRenaud used Ask the Experts™
on
Hello EE,

Im trying to do this linq query :


            Dim qx = (From m In MyItems
                         Where arrString.All(Function(v) m.Value.Contains(v))
                         Let row = rowID
                         Let myKey = m.Key
                         Let myValue = m.Value
                     ).OrderBy(Function(n) n.myKey) _
                      .Select(Function(t) New With {t.row, t.myKey, t.myValue})

Open in new window



it does not stops while running my software, but if I place a breakpoint, and I try to see whats inside "qx", it says : Error Type expected"

the goal is to return 3 variables, (Row, myKey, myValue),  thats why I cannot do  .ToDictionnary() or .ToList()  I thought I needed to do Select New With since I have more than 2 varaibles

also I wanted to OrderBy in my LINQ
do you see any problem looking at it ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
i think I fixed it myself,


this seems to work :

            Dim qx = (From m In MyItems
                      Where arrString.All(Function(v) m.Value.Contains(v))
                      Order By m.Key
                      Select New With
                      {
                        Key .Key = m.Key,
                        Key .Value = m.Value
                      }).AsEnumerable().Select(Function(k, i) New With {.Key = k.Key, .Value = k.Value, .Rank = i + 1}).ToList()

Open in new window

Senior Software Engineer
Top Expert 2009
Commented:
There is no need for the first select, this should work as well:
 Dim qx = (From m In MyItems
                      Where arrString.All(Function(v) m.Value.Contains(v))
                      Order By m.Key
                      ).Select(Function(k, i) New With {.Key = k.Key, .Value = k.Value, .Rank = i + 1}).ToList()

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial