Development With A Dot

Blog on development in general, and specifically on .NET

ADO.NET Data Service Interceptors

There are two possible interceptions you can perform on an ADO.NET Data Service:

  • Query interception: intercept a query made for an entity in order to enforce a restriction;
  • Change interception: intercept a request for updating an entity and possibly cancel it, or change the entity.

Query interceptions are achieved by marking a method with attribute [QueryInterceptor]; the method must have the following signature:

[QueryInterceptor("Author")]
public Expression<Func<Author, Boolean>> OnFilterAuthor()
{
    return (author => author.Name == "Ricardo Peres");
}

Regardless of the query that you specify on the client proxy or the URL, this restriction is always enforced. The name and visibility are ignored.

Interception queries, on the other hand, allow you to change the entity that is being submitted for persistence, or cancel the operation totally. Decorate a method with a [ChangeInterceptor] attribute and add this arguments:

[ChangeInterceptor("Author")]
public void OnChangeAuthor(Author author, UpdateOperations operations)
{
    if (operations == UpdateOperations.Add)
    {
nbsp;       author.Name = "Ricardo Peres";
    }}

Once again, the visibility and name do not count.

Bookmark and Share

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)