Help with linq to sql compiled query
- by stackoverflowuser
Hi
I am trying to use compiled query for one of my linq to sql queries. This query contains 5 to 6 joins. I was able to create the compiled query but the issue I am facing is my query needs to check if the key is within a collection of keys passed as input. But compiled queries do not allow passing of collection (since collection can have varying number of items hence not allowed).
For instance
input to the function is a collection of keys. Say: List<Guid> InputKeys
List<SomeClass> output = null;
var compiledQuery = CompiledQueries.Compile<DataContext, IQueryable<SomeClass>>(
(context) => from a in context.GetTable<A>()
where InputKeys.Contains(a.Key)
select a);
using(var dataContext = new DataContext())
{
output = compiledQuery(dataContext).ToList();
}
return output;
Is there any work around or better way to do the above?