none
Sharing IQueryable between CompiledQueries RRS feed

  • Question

  • Hello,

     I'd like to use compiled queries to retrieve my data but I'm not able to share a common IQueryable between those compiled queries.

     I have a base query which express the way to retrieve data doing join between my tables.

     I have 3 compiled queries using this base query : one without filter, one with id filter, one with data paging filters.

     I did not find a way to use this base query within compiled queries.

     Is there a way to do something like this :

      static readonly Func<Context,  int> compiledQueryById =
          CompiledQuery.Compile<Context,  int>(
                  (context, id) => ( from x in GetBaseQuery(context)
                                             select  x
                                             where x.Id == id  ));

      static readonly Func<Context,  int, int> compiledPagedQuery =
            CompiledQuery.Compile<Context,  int, int>(
                  (context, skip, take) => ( from x in GetBaseQuery(context)
                                                         select  x).Skip(skip).Take(take));

      Or do I have to explicitly write my base query in all my compiled queries ?

    Thanks,

    Yoann

    Wednesday, March 21, 2012 3:27 PM

Answers

  • Hi Yoke78,

    Welcome to MSDN Forum.

    You need to write the base query in all of the 3 compiled queries. Further more, in the code, the last parameter of Func delegate is the result type, so, you need modify the two Func delegate above as below

    Func<Context,int,IEnumerable<the resualt type>>
    
    Func<context,skip,take,IEnumerable<the result type>>

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Yoke78 Monday, March 26, 2012 9:06 AM
    • Unmarked as answer by Yoke78 Monday, March 26, 2012 9:07 AM
    • Marked as answer by Yoke78 Monday, March 26, 2012 9:07 AM
    Monday, March 26, 2012 7:27 AM
    Moderator

All replies

  • Hi Yoke78,

    Welcome to MSDN Forum.

    I will do more research on this issue and come back as soon as possible. Thanks for your understanding.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 23, 2012 9:47 AM
    Moderator
  • Hi Yoke78,

    Welcome to MSDN Forum.

    You need to write the base query in all of the 3 compiled queries. Further more, in the code, the last parameter of Func delegate is the result type, so, you need modify the two Func delegate above as below

    Func<Context,int,IEnumerable<the resualt type>>
    
    Func<context,skip,take,IEnumerable<the result type>>

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Yoke78 Monday, March 26, 2012 9:06 AM
    • Unmarked as answer by Yoke78 Monday, March 26, 2012 9:07 AM
    • Marked as answer by Yoke78 Monday, March 26, 2012 9:07 AM
    Monday, March 26, 2012 7:27 AM
    Moderator
  • Hello Allen,

     Thanks a lot for your investigations and quick reply.

    Yoann

    Monday, March 26, 2012 9:09 AM