I'd like some expert advice on this. I've used compiled queries before, but for this particular case, i'm not sure whether it's appropriate.
It's a search form where the query changes and is dependent on what is being searched on.
static Func<DBContext, int, IQueryable<Foo>> Search = CompiledQuery.Compile( (DBContext db, int ID) => db.Person .Where(w => w.LocationID = ID) .Select(s => new Foo { Name = s.PersonName, Age = s.Age, Location = s.LocationName, Kin = s.Kin })); Now if someone fills in the search box, i want to extend the query by adding another Where statement to the query:
var query = Search(context, 123); query = query.Where(w => w.Name.Contains(searchString)); So my question is, is it returning all the results where LocationID == 123, then checking the results for a searchString match? Or is it actually extending the compiled query?
If it's the former (which i suspect it is), should scrap the CompiledQuery and just create a method that extends the query then return it as a list?
Also, what are the best practices for CompiledQuery usage and is there a guideline of when they should be used?
Note: I'm using the above in an ASP.NET website with Linq to SQL. Not sure if that makes any difference.
Thanks