4 Answers, 1 is accepted
0
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).
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.
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:
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.
<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?
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
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:
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.
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.
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>(); |
} |
} |
public IQueryable<Order> Orders |
{ |
get |
{ |
return StoredProcedure.Order10248(ObjectScopeProvider1.ObjectScope()).AsQueryable<Order>(); |
} |
} |
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.