Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> v4. add a predicateExpression to the Odata query
 

Pages: 1
LLBLGen Pro Runtime Framework
v4. add a predicateExpression to the Odata query
Page:1/1 

  Print all messages in this thread  
Poster Message
raist
User



Location:
Madrid, Spain
Joined on:
19-Apr-2010 23:57:10
Posted:
114 posts
# Posted on: 22-Aug-2013 17:40:53.  
We have tried the Odata services with VS 2010 and llblgen 4.0: awesome!!
But we are trying to get more control on the results, injecting a dynamic filter (predicateExpression) based on the authenticated userId. Is it possible? How and where can we plug it?
Thanks in advance.
  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8150 posts
# Posted on: 23-Aug-2013 07:12:28.  
- Wouldn't be easier to use WebGet methods for that? (or even Controllers)

- How are you authenticating the user, and how would you know how to create the dynamic filter and inject that on the IQueryable?


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
raist
User



Location:
Madrid, Spain
Joined on:
19-Apr-2010 23:57:10
Posted:
114 posts
# Posted on: 23-Aug-2013 08:10:56.  
We can inject the auth realm directly in the httpHeaders (eg. basic auth or session cookie with previous auth). Trying right now.
Once we have the realm we can get the userId and the asociated authorization filters for each entity (ex. Product.ProviderId == userId.CompanyId).
We where considering custom WebGet methods (or even WebAPI) too, but:
- 1. We 'd lose all the OData clients already developed (JayData.js, Data.Services.Client...)
- 2. We'd lose the expressiveness of OData and go to reinvent the API, as in Matt Jcowan solution with ServiceStack (really great, indeed).
http://www.mattjcowan.com/funcoding/2013/03/10/rest-api-with-llblgen-and-servicestack/
We could intercept the query at the DAL level, but somehow it doesn't feel right.

TIA,
Jose
  Top
raist
User



Location:
Madrid, Spain
Joined on:
19-Apr-2010 23:57:10
Posted:
114 posts
# Posted on: 23-Aug-2013 09:58:45.  
It was easier as thought: insert QueryInterceptors in the Service class
Code:

[QueryInterceptor("Product")]
public Expression<Func<ProductEntity, bool>> OnReadProducts()
{
    return o => true; // context.Product.Where(p => p.CategoryId == 2); returns 12 products
    return o => o.Discontinued == false; // same query returns 11 products
}


Thanks


  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
38092 posts
# Posted on: 23-Aug-2013 10:55:45.  
indeed, that's what they're there for Regular Smiley
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
raist
User



Location:
Madrid, Spain
Joined on:
19-Apr-2010 23:57:10
Posted:
114 posts
# Posted on: 23-Aug-2013 10:59:45. Goto attachments  
It simply worked fine!!! (As usual)
I share the VS 2010 solution with
- Llblgen v.4.0 adapter DAL projects (2)
- Northwind service
- Console client

NOTE:
1. Change the connection string in web.config
2. Install the nuget Microsoft.Data.Services packages on both the client and service projects
Code:
PM>Install-Package Microsoft.Data.Services -version 5.3.0.0


Interesting parts:
In NorthwindService.svc.cs:
- Hook to CustomAuthenticationProvider.Authenticate (from http://blogs.msdn.com/b/astoriateam/archive/2010/07/19/odata-and-authentication-part-4-server-side-hooks.aspx)
- Little QueryInterceptor OnReadProducts

In ClienteOData.Program:
- Two changes to the generated NorthwindService constructor
- Added constructor DataServiceProtocolVersion parameter (default V2). To support OData V3
- Added hook to add the authentication header (also from http://blogs.msdn.com/b/astoriateam/archive/2010/05/24/odata-and-authentication-part-3-clientside-hooks.aspx)
Code:
this.SendingRequest += OnSendingRequest;

- UpdateObject call

Regards,

Jose


  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14639 posts
# Posted on: 23-Aug-2013 11:42:32.  
Thanks for the feedback.
Surely others taking the same path would appreciate it.
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.