如何拦截实体之间添加/删除链接的要求 [英] How to intercepte requrests for adding/removing links between entities

查看:97
本文介绍了如何拦截实体之间添加/删除链接的要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

在应用程序中,我们需要在添加和/或删除实体之间的链接时进行授权。说实体A和B,以及A和B之间的多对多关系。实体框架是引擎盖下的数据提供者。 所以在A中,B的导航
属性是B的列表,而在B中,还有A的导航属性,也是As的列表。

In an application, we need to do authorization when adding and/or removing links between entities. Say entity A and B, and a many-to-many relation between A and B. Entity Framework is the data provider under the hood.  So in A, there is a navigation property to B, which is a list of Bs, while in B, there is also a navigation property to A, which is also a list of As.

我们在A和B上都定义了一个查询拦截器和一个更改拦截器。我们尝试了两种添加链接的方法:

We've defined a query interceptor and a change interceptor on both A and B. We tried 2 ways of adding a link:

1。将B添加到A:

POST /OData/OData.svc/As(1)/$links/Bs HTTP / 1.1,在邮件正文中指定B;

POST /OData/OData.svc/As(1)/$links/Bs HTTP/1.1, with B specified in the message body;

在这种情况下,调用A的更改拦截器,但发现A的状态为"未更改"。

In this case, the change interceptor for A is called but found A's status is "Unchanged".

2。添加A到B:

POST /OData/OData.svc/Bs(1)/$links/As HTTP / 1.1,在邮件正文中指定了A;

POST /OData/OData.svc/Bs(1)/$links/As HTTP/1.1, with A specified in the message body;

在这种情况下,调用B的更改拦截器,但发现B的状态为"Unchanged"。

In this case, the change interceptor for B is called but found B's status is "Unchanged".

在任何一种情况下,我们都可以分析http请求和http消息正文,以确定哪个关系将要更改,然后相应地进行授权。然而,它并非如此直截了当。有没有更好的方法呢?

In either case, we may analyze the http request and the http message body to figure out which relation is going to change, and then do the authorization accordingly. However, it is not so straight forward and tedeous. Is there a better way to do this?

谢谢。

XH

推荐答案

我相信这是一个错误,我已经为WCF数据服务团队提交了一个。在应用更改之前调用更改拦截器 - 在修复之后状态不会保持不变,并且EF上下文应该能够告诉您链接上已更改
的内容。

I beleive this is a bug and I have filed one for the WCF Data Services team. The change interceptor is being called before the change is applied - after a fix the status would not be unchanged and the EF context should be able to tell you what has changed on the link.

不幸的是,我不知道在处理有效载荷之前有一种简单的方法。

Unfortunetly, I am not aware of an easy way to get at the payload before it is processed.


这篇关于如何拦截实体之间添加/删除链接的要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆