简体   繁体   English

检测到类型不兼容的二元运算符。 找到运算符类型“Equal”的操作数类型“Edm.Guid”和“Edm.String”

[英]A binary operator with incompatible types was detected. Found operand types 'Edm.Guid' and 'Edm.String' for operator kind 'Equal'

I am getting the following exception when calling OData from my Kendo ListView:从我的 Kendo ListView 调用 OData 时出现以下异常:

"A binary operator with incompatible types was detected. Found operand types 'Edm.Guid' and 'Edm.String' for operator kind 'Equal'" “检测到类型不兼容的二元运算符。发现运算符类型“Equal”的操作数类型“Edm.Guid”和“Edm.String””

<\/blockquote>

DECODED FILTER:<\/strong>解码过滤器:<\/strong>
$filter=OrganizationId eq '4c2c1c1e-1838-42ca-b730-399816de85f8' $filter=OrganizationId eq '4c2c1c1e-1838-42ca-b730-399816de85f8'

ENCODED FILTER:<\/strong>编码过滤器:<\/strong>
%24filter=OrganizationId+eq+%274c2c1c1e-1838-42ca-b730-399816de85f8%27 %24filter=组织Id+eq+%274c2c1c1e-1838-42ca-b730-399816de85f8%27

HAVE ALSO UNSUCESSFULLY TRIED THESE FILTERS:<\/strong>也没有成功地尝试过这些过滤器:<\/strong>
$filter=OrganizationId eq guid'4c2c1c1e-1838-42ca-b730-399816de85f8' $filter=OrganizationId eq guid'4c2c1c1e-1838-42ca-b730-399816de85f8'
$filter=OrganizationId eq cast('4c2c1c1e-1838-42ca-b730-399816de85f8', Edm.Guid) $filter=OrganizationId eq cast('4c2c1c1e-1838-42ca-b730-399816de85f8', Edm.Guid)

MY WEB API CALL LOOKS LIKE:<\/strong>我的 WEB API 调用看起来像:<\/strong>

 \/\/ GET: odata\/Sites [HttpGet] [EnableQuery] public IHttpActionResult GetSites(ODataQueryOptions<Site> queryOptions) { IQueryable<Site> sites = null; try { queryOptions.Validate(_validationSettings); sites = _siteService.GetAll().OrderBy(x => x.SiteName); if (sites == null) return NotFound(); } catch (ODataException ex) { TraceHandler.TraceError(ex); return BadRequest(ex.Message); } return Ok(sites); }<\/code><\/pre>

MY JAVASCRIPT KENDO DATASOURCE LOOKS LIKE:<\/strong>我的 JAVASCRIPT KENDO 数据源看起来像:<\/strong>

 var dataSource = new kendo.data.DataSource({ filter: { field: "OrganizationId", operator: "eq", value: that.settings.current.customer.id }, schema: { data: function (data) { return data.value; }, total: function (data) { return data.length; } }, serverFiltering: true, serverPaging: true, transport: { parameterMap: function (options, type) { var paramMap = kendo.data.transports.odata.parameterMap(options); \/\/ Remove invalid Parameters that Web API doesn't support delete paramMap.$inlinecount; \/\/ <-- remove inlinecount delete paramMap.$format; \/\/ <-- remove format delete paramMap.$callback; \/\/ <-- remove callback \/\/ PLEASE NOTICE: That I have tried reformatting unsuccessfully \/\/paramMap.$filter = paramMap.$filter.replace("OrganizationId eq ", "OrganizationId eq guid"); \/\/paramMap.$filter = "OrganizationId eq cast('81de6144-987c-4b6f-a9bd-355cb6597fc1', Edm.Guid)"; return paramMap; }, read: { url: buildRoute('odata\/Sites') , dataType: 'json' } }, type: 'odata' });<\/code><\/pre>"

If the OData service is of protocol version V4, the correct query URL should be: 如果OData服务是协议版本V4,则正确的查询URL应为:

$filter=OrganizationId eq 4c2c1c1e-1838-42ca-b730-399816de85f8

No single quotes is required. 不需要单引号。

I ran into this error querying OData 4.0 through Microsoft Dynamics. 我遇到了这个错误,通过Microsoft Dynamics查询OData 4.0。 The other answers here didn't help unfortunately, even though they are exactly right. 不幸的是,这里的其他答案并没有帮助,即使它们是完全正确的。 My issue was more with handing EntityReference's in filters. 我的问题更多的是在过滤器中处理EntityReference。

I ended up having to adjust my filter to something like this, to target the foreign key properly. 我最终不得不调整我的过滤器,以适当地定位外键。 In the example below 'parentaccountid' is the foreign key in the entity I was querying. 在下面的示例中,'parentaccountid'是我查询的实体中的外键。 'accountid' is the primary key in the accounts entity. 'accountid'是账户实体的主要关键。

/opportunities?$select=opportunityid&$filter=parentaccountid/accountid eq 5e669180-be01-e711-8118-e0071b6af2a1

Every value which is having kind of an id to another entity reference in ms crm, should be evaluated like this. 每个以ms crm为另一个实体引用的id的值都应该像这样评估。

 $filter=_foodValue eq 593687F4-8B0C-E811-81B1-91CF10505DB5 

Does not require quotes or guid string. 不需要引号或guid字符串。

使用 PowerBi Rest API,我可以通过将 GUID 放在单引号内来解决问题: https<\/a> :\/\/api.powerbi.com\/v1.0\/myorg\/groups?%24filter=id%20eq%20'9c02ab25-0e94 -4835-92e6-62ac6460acd0'<\/a>

"

请试试

$filter=OrganizationId%20eq%20guid%27067e6162-3b6f-4ae2-a171-2470b63dff02%27

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM