This is a migrated thread and some comments may be shown as answers.

OA And Query Interceptors

4 Answers 106 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jonathan
Top achievements
Rank 1
Jonathan asked on 14 Jul 2009, 02:00 PM
So does OpenAccess support ADO.net Data Service's Query interceptors?

4 Answers, 1 is accepted

Sort by
0
Dimitar Kapitanov
Telerik team
answered on 17 Jul 2009, 02:48 PM
Hi Jonathan Marbutt,
Can you elaborate a bit  what support of query interceptors do you require with OpenAccess?
Currently we are not generating IQUeryable endpoints automatically, but we have a sample data context implementation that can be used for inheritance and then manually you can add the endpoints. That said we have a sample application that demonstrates this here.  It comes both in C# and VB.NET flavor.
Regarding the interceptors here is a sample code that demonstrates the usage with our Silverlight application (Northwind data model).

   [QueryInterceptor("Orders")] 
   public Expression<Func<Order,bool>> OnQueryOrders() 
   { 
       //return o => o.Customer.ContactName == 
       //                  HttpContext.Current.User.Identity.Name; 
       return o => o.OrderID == 10252; 
   } 
 
   [ChangeInterceptor("OrderDetails")] 
   public void OnChangeCategories(OrderDetail c, UpdateOperations ops) 
    { 
        if (ops == UpdateOperations.Add || 
           ops == UpdateOperations.Change) 
        { 
            // single word, no spaces 
            if (c.ProductID == 42) 
            { 
                throw new DataServiceException(400, 
                            "Category names must consist of a single word"); 
            } 
        } 
    } 

You should add this to the body of the OADataService (part of the sample application, resides in the App_Code folder). This code snippets demonstrates both type of interceptors - query interceptors and change interceptors.

I hope this helps.

Best wishes,
Dimitar Kapitanov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jonathan
Top achievements
Rank 1
answered on 17 Jul 2009, 03:17 PM
We are using the query interceptors to handle some security context so it basically looks something like this:

    <QueryInterceptor("People")> _ 
    Public Function OnQueryPeople() As Expression(Of Func(Of Person, Boolean)) 
        Return Function(p) p.CustomerID = CurrentUser.CustomerID 
    End Function 


This way from the silverlight app it doesn't have to know what the security context is and where to use it. So basically the silverlight app can just say basically "Select * From People" and it knows how to filter based on the current user

I wish there was a way I could almost do something to where I could write one interceptor for almost all my tables. Basically 90% of our tables have a CustomerID in it, I wish there was a way to write a global interceptor and make sure that table had the customerid and if so filter on it instead of having to write an interceptor for each table.
0
Jonathan
Top achievements
Rank 1
answered on 17 Jul 2009, 09:34 PM
Also is there a way to make stored procedure calls from an ADO.net Data Service or do I have to do it from RIA or WCF service?

For example if I have an SP that will get all the People in the db, and I want to over write the OnQueryPeople to call this sp instead of just doing a linq to sql, is that possible?
0
PetarP
Telerik team
answered on 22 Jul 2009, 03:53 PM
Hello Jonathan Marbutt,
what the query interceptor gives you is the flexibility to further filter the result. You can apply additional rules to the query being executed but you cannot change the complete result being returned. To change the way your information is retrieved you can easily alter the service end point.
Typically you have something similar to this:
 public IQueryable<Order> Orders 
        { 
            get 
            { 
                return this.GetAll<Order>(); 
            } 
        } 
The above code will return all orders. You can however change it with a stored procedure call and convert the result to an Iqueryable of type Order.
public IQueryable<Order> Orders 
        { 
            get 
            { 
                return StoredProcedure.Order10248(ObjectScopeProvider1.ObjectScope()).AsQueryable<Order>(); 
            } 
        } 
This way the stored procedure Order10248 will be used when ever the service reaches to the Orders endpoint. You can later apply any Query Interceptor to the result of the stored procedure as you would normally do.
As for your second question unfortunately it is not possible to have one global interceptor for all your classes even though they all contain the same field.

Kind regards,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Dimitar Kapitanov
Telerik team
Jonathan
Top achievements
Rank 1
PetarP
Telerik team
Share this question
or