0

I am trying to convert sql to entity and I need to select distinct items. I thought this would work but its returning all the rows instead of the distinct items.

  Dim OrderNos = (From r In Orders.R3Delivery Where r.mainOrderNumber <> "" Select r).Distinct().ToList()
    For Each thisentry In OrderNos
        cbOrderNumbers.DisplayMember = thisentry.mainOrderNumber
        cbOrderNumbers.ValueMember = thisentry.mainOrderNumber

    Next

Also is their any good free sql to linq tools out their linquer good but its like 60 quid

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
c-sharp-and-swiftui-devni
  • 3,743
  • 4
  • 39
  • 100
  • I believe this has been answered on [this SO question.](http://stackoverflow.com/questions/6556077/distinct-in-linq-with-anonymous-types-in-vb-net) – Drew Hayes May 12 '14 at 17:01
  • `DisplayMember` and `ValueMember` should not be the same field. You should not be setting these in a loop either - they are getting overwritten each iteration. – OneFineDay May 12 '14 at 17:01
  • ``DisplayMember`` and ``ValueMember`` can be the same. I do agree that they shouldn't be the same. – Adam Zuckerman May 12 '14 at 17:06

1 Answers1

1

The problem is that the Distinct() is comparing the entire object being returned, not just the order number.

If you only need the order numbers, changing this line should get you there:

Dim OrderNos = (From r 
                In Orders.R3Delivery 
                Where r.mainOrderNumber <> "" 
                Select r.mainOrderNumber).Distinct().ToList()

If you need the whole object, then it gets more complicated.

Adam Zuckerman
  • 1,633
  • 1
  • 14
  • 20