OData / ADO.NET Data Services using LINQ-to-SQL with decryption layer
I wrote an application using LINQ-to-SQL that submits a web form to a database. I am removing LINQ-to-SQL using the repository pattern.
This repository has basic methods: Get (), Save (), etc.
As a development project, I needed to encrypt certain fields in a form. This was trivial since I just added encryption calls to the Get (), Save () methods in the repository.
Now I want to put an OData layer above it to allow RESTful fetching from MS Excel 2010 (when it exits). This works for me, after stumbling around a few unhelpful error messages etc.
However, obviously these encrypted fields are still encrypted. My repository template would decode this for me. As far as I know, I have to bind my oData service directly to the LINQ-to-SQL context for the schema, etc., in order to work - unless I enter a whole world of pain (any urls are evaluated).
Is there a way that I can insert my encryption / decryption layer into the request so that decryption is done on the fly? I looked at the OnStartProcessingRequest () overload of the DataService, but that doesn't seem to be helpful.
a source to share
You don't need to communicate directly with L2S to open the OData service. You can write your own Context class and use the Reflection provider directly to infer the model from the IQueryable properties provided by your class.
Note. The L2S approach you are using is just using the Reflection provider.
The key to this is simply wrapping L2S DataContext requests ( see this ) so you can inject yourself into the query execution:
- Just move the generated expression to L2S and run the query against the database.
- When the results are returned from L2S, you can enumerate them in memory doing on-the-fly decryption before returning them to data services.
For more information on the Reflection provider visit this post .
Hope it helps
OData / Data Service Program Manager
a source to share