OData 筛选器和 Guid 字段的问题
我正在尝试使用 OData 来运行一些代码。下面的代码似乎不起作用。
ds 是 OpenDataServiceProxy。
adapterTypeId 是 Guid 的字符串表示形式。
adapterName 是一个字符串名称
ds.query('/DataAdapters?$filter=DataAdapterType.DataAdapterTypeId eq guid(\'' + adapterTypeId + '\') and Name eq \'' + adapterName + '\'', ifmgr_CreateAdapter_Step1, onGenericFailure, 'Error');
上面的行给出以下错误:
“System.Boolean”类型的表达式预计位于位置 0。
如果我删除过滤器的 Guid 部分,以便它仅使用“Name” ”部分工作正常。
DataAdapters 表字段“DataAdapterTypeId”是“DataAdapterTypes”表 DataAdapterTypeId 字段的外键。
谁能发现我做错了什么吗?
-------------------编辑----------------------
好的,我已经更换了过滤器如下图所示。我不再收到错误,而是返回大量结果,而不是一条与过滤器匹配的记录。谁能告诉我为什么不过滤?
ds.query('/DataAdapters?($filter=Name eq \'' + adapterName + '\' and $filter=DataAdapterTypeId eq guid\'' + adapterTypeId + '\')', ifmgr_CreateAdapter_Step1, onGenericFailure, '');
I’m trying to get some code working using OData. The following bit of code doesn’t seem to work.
ds is OpenDataServiceProxy.
adapterTypeId is the string representation of a Guid.
adapterName is a string name
ds.query('/DataAdapters?$filter=DataAdapterType.DataAdapterTypeId eq guid(\'' + adapterTypeId + '\') and Name eq \'' + adapterName + '\'', ifmgr_CreateAdapter_Step1, onGenericFailure, 'Error');
The above line give the following error:
Expression of type ‘System.Boolean’ expected at position 0.
If I remove the Guid section of the filter so that it’s just using the “Name” part it works fine.
The DataAdapters table field “DataAdapterTypeId” is foreign keyed to the “DataAdapterTypes” table DataAdapterTypeId field.
Can anyone spot what I’m doing wrong?
-------------------EDIT----------------------
OK, I've changed the filter as shown below. I no longer get an error but get lots of results back rather than one record that matches the filter. Can anyone say why it's not filtering?
ds.query('/DataAdapters?($filter=Name eq \'' + adapterName + '\' and $filter=DataAdapterTypeId eq guid\'' + adapterTypeId + '\')', ifmgr_CreateAdapter_Step1, onGenericFailure, '');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
guid 值的格式需要类似于 guid'' - 有关详细信息,请参阅此: http:// www.odata.org/developers/protocols/overview#AbstractTypeSystem
不知道您想使用 DataAdapterType.DataAdatperTypeId 实现什么目的,但点字符在过滤器表达式中没有特殊含义,因此它可能不会执行您想要的操作。如果您的 DataAdapters 实体集具有 DataAdapterType 类型的实体,并且该实体具有 GUID 类型的属性 DataAdapterTypeId,那么您可以通过简单地对其进行过滤
The guid value needs to be formated like guid'' - see this for details: http://www.odata.org/developers/protocols/overview#AbstractTypeSystem
Don't know what you wanted to achieve with the DataAdapterType.DataAdatperTypeId, but the dot character has no special meaning in the filter expression, so it probably doesn't do what you wanted. If your DataAdapters entity set has entities of type DataAdapterType, which then has a property DataAdapterTypeId which is of type GUID, then you can filter on it by simply
对于 OData v4,在 ASP.NET 上对我有用的是
观察 guid 值周围没有引号或强制转换。如果
adapterTypeId
不是 GUID,则会抛出错误。With OData v4 what works for me on ASP.NET is
Observe no quotes or casts around the guid value. It will throw an error if
adapterTypeId
is not a GUID.您可以找到更新的 URL 约定参考 此处。
You can find the updated URL convention reference here.