linq to sql 查询拦截器

发布于 2024-08-05 23:56:36 字数 468 浏览 2 评论 0原文

我正在考虑实现一些 LINQ to SQL,但很难了解我们如何添加访问控制业务规则,例如客户 a 只能查看他们的订单。 在 ado.net 数据服务中,查询拦截器所做的正是我所追求的,并且可以看到如何检查更新/插入/删除,但是是否有等效的:

[QueryInterceptor("Orders")] 
public IQueryable<Orders> OnQueryOrders(IQueryable<Orders> orderQuery) 
{ 

      return from o in orderQuery 
         where o.Customers.ContactName == HttpContext.Current.User.Identity.Name 
         select o; 
} 

或者我需要通过访问器进行控制: GetOrdersByCustomer(字符串客户ID)

I'm looking at implementing some LINQ to SQL but am struggling to see how we woudl add in access control business rules such as customer a can only view their orders.
In ado.net data services, query intercptors do exactly what I am after, and can see how to check on update / insert / delete, but is there an equivalent of this:

[QueryInterceptor("Orders")] 
public IQueryable<Orders> OnQueryOrders(IQueryable<Orders> orderQuery) 
{ 

      return from o in orderQuery 
         where o.Customers.ContactName == HttpContext.Current.User.Identity.Name 
         select o; 
} 

Or wil I need to control via accessors along the line of:
GetOrdersByCustomer(string customerId)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

习惯成性 2024-08-12 23:56:36

我认为,在这种情况下,更好的解决方案是构建一个位于应用程序层和 LINQ to SQL 类之间的真正业务层。

然后,您将查询业务层,业务层反过来将实现您的所有业务逻辑和过滤。如果架构正确,业务层对于任何编码应用程序层的人来说都是相当透明的,然后每个人都会很高兴。

I think, in this case, the better solution would be to build a true Business Layer that sits between the Application Layer and your LINQ to SQL classes.

You would then query your Business Layer, which in turn would implement all your Business Logic and filtering. If architected properly, that Business Layer could be fairly transparent to anybody coding the Application Layer and then everybody would be happy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文