C# WCF数据服务和RavenDB:get by id提高“;仅通过id进行查询的尝试被阻止…“;

C# WCF数据服务和RavenDB:get by id提高“;仅通过id进行查询的尝试被阻止…“;,c#,wcf,wcf-data-services,odata,ravendb,C#,Wcf,Wcf Data Services,Odata,Ravendb,我正在使用WCF数据服务和RavenDB 在我想到一件事之前,一切似乎都很顺利: 按ID查询 无论哪种方式: /DataService.svc/EntitySet?$filter=ID eq '123' 或: 当我尝试调用其中一个URL时,我得到以下结果: Attempt to query by id only is blocked, you should use call session.Load("123"); instead of session.Query().Where(x=>

我正在使用WCF数据服务和RavenDB

在我想到一件事之前,一切似乎都很顺利: 按ID查询

无论哪种方式:

/DataService.svc/EntitySet?$filter=ID eq '123'
或:

当我尝试调用其中一个URL时,我得到以下结果:

Attempt to query by id only is blocked, you should use call session.Load("123");
instead of session.Query().Where(x=>x.Id == "123");
You can turn this error off by specifying
documentStore.Conventions.AllowQueriesOnId = true;
but that is not recommend and provided for backward compatibility reasons only.
如何中断WCF数据服务以对数据库进行自定义调用,而不是使用session.Query()进行默认调用


据我所知,查询拦截器无法工作,因为它们需要定义一个特定的EntitySet。

我没有一个好的答案。您可以按照错误建议执行操作并更改约定,但它确实会影响性能。如果这是WebAPI,我建议使用单独的加载路径,而不是查询路径,但不确定这在WCF数据服务中是否可行。就我个人而言,读完这本书后,我已经完全放弃了小田。对不起,我不能提供一个直接的解决方案。也许其他人可以。可以通过使用服务操作创建新路由,但我使用JayData作为JavaScript OData框架,不想更改其源代码,以使用我的服务操作,而不是默认操作。。
Attempt to query by id only is blocked, you should use call session.Load("123");
instead of session.Query().Where(x=>x.Id == "123");
You can turn this error off by specifying
documentStore.Conventions.AllowQueriesOnId = true;
but that is not recommend and provided for backward compatibility reasons only.