Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Select Distinct MVC Linq

$
0
0

Hello All. I am sure I am overlooking something but...could someone assist please. I am simply trying to select DISTINCT using the following code....and it is returning a all (even duplicates. Thank you for any assistance.

public JsonResult GetCounties(string statename)
{
var counties = db.Counties.AsQueryable();

if (statename != null)
{
counties = counties.Distinct().Where(c => c.StateName == statename);
}

return Json(counties.Select(p => new { CountyId = p.CountyId, CountyName = p.CountyName }), JsonRequestBehavior.AllowGet);
}


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>