linq to sql 查询拦截器
我正在考虑实现一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,在这种情况下,更好的解决方案是构建一个位于应用程序层和 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.