locked
How to intercepte requrests for adding/removing links between entities RRS feed

  • Question

  • Hi there

    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.

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

    1. Add B to A:

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

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

    2. Add A to B:

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

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

    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?

    Thanks.

    X.H.


    • Edited by XD2040 Friday, March 18, 2011 9:37 PM fixes some typos.
    Friday, March 18, 2011 9:34 PM

All replies

  • 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.


    Shayne Burgess | Program Manager | OData/WCF Data Services
    Monday, June 20, 2011 11:07 PM
    Moderator