使用带有解密层的 LINQ-to-SQL 的 oData/ADO.NET 数据服务
我使用 LINQ-to-SQL 编写了一个应用程序,用于将 Web 表单提交到数据库中。我使用存储库模式抽象了 LINQ-to-SQL。
这个存储库有基本方法:Get()、Save()等。
作为项目的开发,我需要对表单中的某些字段进行加密。这很简单,因为我刚刚添加了对存储库中的 Get()、Save() 方法的加密调用。
现在,我想在其上放置一个 oData 层,以允许从 MS Excel 2010(当它推出时)进行 RESTful 提取。在遇到一些无用的错误消息等之后,我已经完成了这项工作。
但是,显然,这些加密字段仍然是加密的。我的存储库模式将为我解密这些。据我所知,我必须将我的 oData 服务直接绑定到 LINQ-to-SQL 上下文才能使模式等工作 - 除非我进入一个痛苦的世界(任何 URL 都值得赞赏)。
有没有办法将我的加密/解密层插入到请求中,以便“即时”完成解密?我查看了 DataService 的 OnStartProcessingRequest() 重载,但这似乎没那么有用。
I have written an application using LINQ-to-SQL that submits a web form into a database. I absact the LINQ-to-SQL away using a Repository pattern.
This repository has the basic methods: Get(), Save(), etc.
As a development of the project, I needed to encrypt certain fields in the form. This was trivial, as I just added the encryption calls to the Get(), Save() methods in the Repository.
Now, I want to put an oData layer over it, to allow RESTful extraction from MS Excel 2010 (when it comes out). I have this working, after a few stumbles on useless error messages, etc.
However, obviously, those encrypted fields are still encrypted. My repository pattern would have decrypted these for me. As far as I know, I have to directly bind my oData service to the LINQ-to-SQL context for the schema, etc. to work - unless I enter a whole world of pain (any URLs appreciated).
Is there a way I can insert my encryption/decryption layer into the request so decryption is done "on the fly"? I looked at the OnStartProcessingRequest() overload of DataService but this doesn't seem that useful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必直接绑定到 L2S 即可公开 OData 服务。
您可以编写自己的 Context 类,并直接使用 Reflection Provider 从您的类公开的 IQueryable 属性推断模型。
注意:您使用的 L2S 方法也只是使用反射提供程序。
关键是简单地包装 L2S DataContext 的可查询对象 (请参阅此),这样您就可以将自己注入到查询执行中:
有关反射提供程序的详细信息,请查看
希望这对
Alex James
OData / 数据服务项目经理有帮助
You don't have to bind directly to L2S to expose an OData service.
You can write your own Context class and use the Reflection Provider Directly to infer a model from the IQueryable properties your class exposes.
Note: the L2S approach you are using is just using the Reflection provider too.
The key to this is simply wrapping the L2S DataContext's queryables (see this) so you can inject yourself into the query execution:
For more information on Reflection Provider check out this post.
Hope this helps
Alex James
OData / Data Service Program Manager