Created
June 21, 2013 16:03
-
-
Save venblee/5832230 to your computer and use it in GitHub Desktop.
Select Disctinct using Linq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make sure you use DTO and not EF Poco | |
// Else you will get error | |
public List<Models.PostalCode> SearchCity(string searchTerm) | |
{ | |
try | |
{ | |
using (var db = new PmsContext()) | |
{ | |
var pa = db.PostalCodes.Distinct().Where(x => x.town.Contains(searchTerm)).ToList(); | |
List<Models.PostalCode> cities = (from p in db.PostalCodes | |
where p.town.Contains(searchTerm) | |
select new Models.PostalCode() | |
{ | |
town = p.town, | |
} | |
).Distinct().ToList(); | |
// return db.PostalCodes.Where(x => x.town.Contains(searchTerm)).Distinct().ToList(); | |
return cities; | |
} | |
} | |
catch (Exception ex) | |
{ | |
} | |
return new List<Models.PostalCode>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment