I am trying to select the distinct rows from the database using the code given below. When i run this query it does not return the result what i am expected. I need distinct city names into dropdown control.
using (var context = new CountryEntities())
{
var city = (from u in context.Cities
where u.StateId == StateID
select new
{
cityId = u.CityId,
cityName = u.CityName
}).Distinct();
cboCity.DataSource = city.ToList();
cboCity.DataValueField = "CityId";
cboCity.DataTextField = "CityName";
cboCity.DataBind();
cboCity.Items.Insert(0, new ListItem("--Select--", "0"));
}
My database table is
What should i do. Please help me. Thanks in advance.