2
votes

Background:
I have a WCF Data Service that is hooked up to SQL Server via Entity Framework.

One of my tables has a column that is type varbinary. It is holding an XML string of data that should be compressed on the way into the database (via a different service).

My Question:
I would like to be able to un-compress this varbinary data and change it to an XML or string object when a client queries it via the WCF Data Service (OData).

Is this possible? If so, where would I plug in?

1

1 Answers

0
votes

You can take advantage of ChangeInterceptors in Odata as shown here

http://msdn.microsoft.com/en-us/library/dd744842.aspx

When Adding a changeInterceptor to an Entity call you will have access to its state and depending on its state you can perform your task for example here is a change interceptor for one of my Entities, "Term"

[ChangeInterceptor("Term")]
public virtual void OnChangeTerm (Term reqObj, UpdateOperations operations){
    OnChangeInterceptor<Term>(reqObj, operations, CurrentDataSource);
}


protected virtual void OnChangeInterceptor<TEntity>(TEntity entity, UpdateOperations operations, IDataContext currentDataSource)
{
    switch (operations){
                    case UpdateOperations.Add:
                        ServiceController.OnAddEntityRequest(entity, currentDataSource);
                        break;
                    case UpdateOperations.Change:
                        ServiceController.OnUpdateEntityRequest(entity, currentDataSource);
                        break;
                    case UpdateOperations.Delete:
                        ServiceController.OnDeleteEntityRequest(entity, currentDataSource);
                        break;
    }

}