I’m trying to create a simple address screen where the user has a single “google” style query box which searches across all address fields i.e. address line 1, town, city, post code etc.
I’m using .net and EF with an SQL database. I’ve tried
IEnumerable<T> results = from x in dbSet
where (x.AddressLine1 + x.AddressLine2 +
x.AddressLine3 + x.Town + x.City +
x.County + x.Postcode).Contains(Query)
select x;
This does not match any results when it should. If i change it to
IEnumerable<T> results = from x in dbSet
where x.AddressLine1.Contains(Query)
select x;
It matches and returns results but obviously its not searching across all fields. First question why is my first example not working and second is this the best way to implement this or is it going to struggle under pressure.
Try this:
For more complicated searches using Linq, I use LinqKit