Question

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

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top