locked
Intercepting IQueryable to create DSPResource in custom provider RRS feed

  • Question

  • Hello,

    I am slowly moving on with custom provider for MongoDB. Since DSPContext implementation in OData provider toolking assumes in-memory result list, I need to replace it with my own implementation that supports deferred query execution. There is a decent LINQ provider for MongoDB called FluentMongo, but my challenge is that I can't just return naked Mongo documents since I need to wrap resulting entries in instances of DSPResource. Does anybody have tips of how this can be achived? I trace query execution and see that execution results are handled by WCF Data Services internals, and of course it fails to cast them into DSPResource for further processing. I will be grateful for any hints of how this can be achived.

    UPDATE. I've found blog posts by Vitek and Alex that shows how to use InterceptingQueryProvider. But I wounder what methods my custom visitor should visit: VisitMethodCall and VisitInvocation or anything else?


    Vagif Abilov


    • Edited by Vagif Abilov Friday, February 17, 2012 2:33 PM Updated question
    Thursday, February 16, 2012 4:54 PM

Answers

  • Hi,

    You need to wrap the IQueryable returned by your provider and "post-process" the results. The intercepting query provider is half way there. There's a little better sample here: http://blogs.msdn.com/b/vitek/archive/2012/01/07/projections-in-custom-providers-simple-solution.aspx.

    The blog post describes something a little different, but it does wrap the IQueryable and post-process the results. In this sample it does something with projections, in your case it would be simpler since you would just get the IEnumerator from the original IQueryable and "wrap" it with your post-processing.

    You could even use the same trick the .Select as the blog post does, just with different code in it.

    Thanks,


    Vitek Karas [MSFT]

    • Marked as answer by Vagif Abilov Saturday, February 18, 2012 9:00 AM
    Friday, February 17, 2012 7:26 PM
    Moderator

All replies

  • Hi,

    You need to wrap the IQueryable returned by your provider and "post-process" the results. The intercepting query provider is half way there. There's a little better sample here: http://blogs.msdn.com/b/vitek/archive/2012/01/07/projections-in-custom-providers-simple-solution.aspx.

    The blog post describes something a little different, but it does wrap the IQueryable and post-process the results. In this sample it does something with projections, in your case it would be simpler since you would just get the IEnumerator from the original IQueryable and "wrap" it with your post-processing.

    You could even use the same trick the .Select as the blog post does, just with different code in it.

    Thanks,


    Vitek Karas [MSFT]

    • Marked as answer by Vagif Abilov Saturday, February 18, 2012 9:00 AM
    Friday, February 17, 2012 7:26 PM
    Moderator
  • Thanks Vitek, it looks like this is what I need. I will give it a try.

    Vagif


    Vagif Abilov

    Saturday, February 18, 2012 9:00 AM