order by and distinct in entity framework

The following event handler is returning it's list but it is not distinct. There are still many duplicates in the list.Any thoughts?

Protected Sub ddlState_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlState.SelectedIndexChanged
    If IsPostBack Then
        ddlCity.Items.Clear()
        Dim context As New teckEntities()
        Using context
            'Dim query = From c In context.counties Where c.stateid = ddlState.SelectedValue Select c.countyname, c.id
            Dim query = From c In context.ziptaxes Where c.StateID = ddlState.SelectedValue Order By c.City Select c.City, c.ZipTaxId
            query.Distinct()
            ddlCity.DataSource = query.ToList()
            ddlCity.DataValueField = "ziptaxid"
            ddlCity.DataTextField = "City"
            ddlCity.DataBind()
        End Using
    End If

End Sub

Answers


You should assign the return value of the query after you have applied the distinct filter.

 ddlCity.DataSource = query.Distinct().ToList()
 ddlCity.DataValueField = "ziptaxid"
 ddlCity.DataTextField = "City"
 ddlCity.DataBind()

Need Your Help

Should I use null to see if a variable is empty in PHP?

php performance

Which is better to use when I use _GET['something here'] for a variable to check if it is empty or not

How to pickup multiple images from photo gallery in iOS 8 Swift

ios swift

I'm building an app for iOS 8 using Swift and I need to allow the user select more than one image from the photo gallery. But all code examples using UIImagePickerController works with just one pho...