开发者

Problems with an OData filter and a Guid field

开发者 https://www.devze.com 2023-01-19 09:58 出处:网络
I’m trying to get some code working using OData. The following bit of code doesn’t seem to work. ds is OpenDataServiceProxy.

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'v开发者_开发技巧e 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, '');


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

DataAdapterTypeId eq guid'<value>'


With OData v4 what works for me on ASP.NET is

'DataAdapterTypeId eq ' + adapterTypeId

Observe no quotes or casts around the guid value. It will throw an error if adapterTypeId is not a GUID.


You can find the updated URL convention reference here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号