Help with linq to sql compiled query
        Posted  
        
            by 
                stackoverflowuser
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by stackoverflowuser
        
        
        
        Published on 2011-02-08T23:22:35Z
        Indexed on 
            2011/02/08
            23:25 UTC
        
        
        Read the original article
        Hit count: 452
        
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?
© Stack Overflow or respective owner