Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to filter/intercept query? #13

Open
NKnusperer opened this issue Nov 8, 2013 · 3 comments
Open

How to filter/intercept query? #13

NKnusperer opened this issue Nov 8, 2013 · 3 comments

Comments

@NKnusperer
Copy link

Hello, I want to intercept a query in a way that only data are returned that contains a given GUID so the user can only see his own data. How can I do this?

@object
Copy link
Owner

object commented Nov 8, 2013

Can you provide some more details of what's you're trying to achieve? An example? Is this something that must be filtered on a server?

@NKnusperer
Copy link
Author

I just found issue #9 where a sample in VB.Net was posted,so I'am currently using this piece of code which seems to work:

[QueryInterceptor("LogMessages")]
public Expression<Func<DSPResource, bool>> OnPostQuery()
{
    Guid? myApiKey = new Guid("00000000-0000-0000-0000-000000000000");
    return x => (Guid)x.GetValue("ApiKey") == myApiKey;
}

Is this the right way to it?

#Edit:
Is there any way to use the DB model so I could do something like this:

[QueryInterceptor("LogMessages")]
public Expression<Func<LogMessage, bool>> OnPostQuery()
{
    Guid myApiKey = new Guid("00000000-0000-0000-0000-000000000000");
    return x => x.ApiKey == myApiKey;
}

Currently it just throws an exception that the types doesn't match:

The server encountered an error processing the request. The exception message is 'Return type of method 'OnPostQuery' on type 'WCFTest.MongoDataService' is of type 'System.Linq.Expressions.Expression`1[[System.Func`2[[WCFTest.LogMessage, WCFTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' but a type assignable to 'System.Linq.Expressions.Expression`1[[System.Func`2[[DataServiceProvider.DSPResource, DataServiceProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' is required for a query interceptor.'. See server logs for more details. The exception stack trace is: 

at System.Data.Services.DataServiceStaticConfiguration.CheckQueryInterceptorSignature(Type dataServiceType, MethodInfo method, ResourceSet container) at System.Data.Services.DataServiceStaticConfiguration.RegisterCallbacks(Type dataServiceType) at System.Data.Services.DataServiceStaticConfiguration..ctor(Type dataServiceType, IDataServiceMetadataProvider provider) at System.Data.Services.DataService`1.CreateProvider() at System.Data.Services.DataService`1.EnsureProviderAndConfigForRequest() at System.Data.Services.DataService`1.HandleRequest() at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody) at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

@object
Copy link
Owner

object commented Nov 8, 2013

Thanks for an example. I will try to reproduce the exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants