gpt4 book ai didi

javascript - 检测到具有不兼容类型的二元运算符。为运算符种类 'Edm.Guid' 找到操作数类型 'Edm.String' 和 'Equal'

转载 作者:可可西里 更新时间:2023-11-01 02:55:06 26 4
gpt4 key购买 nike

从我的 Kendo ListView 调用 OData 时出现以下异常:

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

解码过滤器:
$filter=OrganizationId eq '4c2c1c1e-1838-42ca-b730-399816de85f8'

编码过滤器:
%24filter=OrganizationId+eq+%274c2c1c1e-1838-42ca-b730-399816de85f8%27

还尝试了这些过滤器但没有成功:
$filter=OrganizationId eq guid'4c2c1c1e-1838-42ca-b730-399816de85f8'
$filter=OrganizationId eq cast('4c2c1c1e-1838-42ca-b730-399816de85f8', Edm.Guid)

我的 Web API 调用看起来像:

// 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);
}

我的 JAVASCRIPT KENDO 数据源看起来像:

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'
});

最佳答案

如果OData服务是协议(protocol)版本V4,正确的查询URL应该是:

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

不需要单引号。

关于javascript - 检测到具有不兼容类型的二元运算符。为运算符种类 'Edm.Guid' 找到操作数类型 'Edm.String' 和 'Equal',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28995757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com