locked
QueryInterceptor : Request error RRS feed

  • Question

  • Hello,

    When I try to use

    [QueryInterceptor("Orders")]
            public IQueryable OnQueryOrders(IQueryable orderQuery)
            {
                var q = from Orders o in orderQuery
                        where o.Customers.ContactName == HttpContext.Current.User.Identity.Name
                        select o;
                return q;
            }


    I have a 'Request Error'  immediatly after launching the site

    Could you help me ?

    Regards

    ArtyProg


    artyprog
    Wednesday, December 24, 2008 9:24 AM

Answers

  • Here's how the query interceptor should look like:

           [QueryInterceptor("Orders")]
           public Expression<Func<Orders,bool>> OnQueryOrders()
           {
              return o => o.Customers.ContactName ==
                                HttpContext.Current.User.Identity.Name
           }

    Hope this helps. For more information about query interceptors, please look at the following whitepaper: http://msdn.microsoft.com/en-us/library/cc907912.aspx

    Thanks
    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, December 25, 2008 11:00 PM
    Moderator
  • Thanks Patrik :-),

    Trying your solution I still had and error until I include the following statement

    using System.Linq.Expressin

    Many Thanks to you and Phani

    Regards

    Salvatore


    artyprog
    • Marked as answer by artyprog Monday, December 29, 2008 9:55 AM
    Friday, December 26, 2008 8:24 AM

All replies

  • Here's how the query interceptor should look like:

           [QueryInterceptor("Orders")]
           public Expression<Func<Orders,bool>> OnQueryOrders()
           {
              return o => o.Customers.ContactName ==
                                HttpContext.Current.User.Identity.Name
           }

    Hope this helps. For more information about query interceptors, please look at the following whitepaper: http://msdn.microsoft.com/en-us/library/cc907912.aspx

    Thanks
    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, December 25, 2008 11:00 PM
    Moderator
  • Hi,
     In addition to Pratik's suggestion  , to access the HttpContext  in the Query Interceptor, you would need to set the
    AspNetCompatibilityRequirementsAttribute on the Data Service.

    See this link for more details about ASP.NET and WCF integration :
    http://msdn.microsoft.com/en-us/library/aa702682.aspx
    Phani Raj Astoria
    Friday, December 26, 2008 6:17 AM
    Moderator
  • Thanks Patrik :-),

    Trying your solution I still had and error until I include the following statement

    using System.Linq.Expressin

    Many Thanks to you and Phani

    Regards

    Salvatore


    artyprog
    • Marked as answer by artyprog Monday, December 29, 2008 9:55 AM
    Friday, December 26, 2008 8:24 AM