【问题标题】:A binary operator with incompatible types was detected. Found operand types 'Edm.Int32' and 'Edm.Int32' for operator kind 'And'检测到类型不兼容的二元运算符。找到运算符类型“And”的操作数类型“Edm.Int32”和“Edm.Int32”
【发布时间】:2018-06-26 16:43:50
【问题描述】:

当我通过 IMobileServiceClient 从我的移动应用程序查询我的 Azure DB 时,我收到以下查询错误:

https://domain.azurewebsites.net/tables/Entities?$filter=(substringof('f',OriginalName) and ((Types and 1) ne 0))&$orderby=Start&$skip=0&$top=20&$select=OriginalName,OriginalSlogan,Description,Start,End,Types,Id,Version,CreatedAt,UpdatedAt,Deleted

The query specified in the URI is not valid. A binary operator with incompatible types was detected. Found operand types 'Edm.Int32' and 'Edm.Int32' for operator kind 'And'."

但是当直接使用查询数据库时

Select * from Entities where ((Types & 1) <> 0)

效果很好。

Transact-SQL Microsoft Docs 中声明按位和运算符对两个整数(32 位类型)有效。 OData Doc 指出 edm.Int32 表示有符号的 32 位整数值。

我的应用中查询的基本部分是

query = query.Where(f => (f.TypesDb & types) != 0);

f.TypesDbtypes 在 C# 代码中都是整数。 (注:f.TypesDb通过json序列化映射到Types

那么为什么类型不兼容呢?

【问题讨论】:

    标签: azure tsql xamarin azure-sql-database azure-mobile-services


    【解决方案1】:

    IMobileServiceClient 将代码中的 &amp; 错误地转换为 URL 过滤器参数中的 andand 被解释为逻辑和,所以类型Edm.Int32 与之不兼容。

    没有办法在URL的过滤参数中使用位与

    作为一个肮脏的解决方法,我现在在数据库中存储一个逗号分隔的 ints 字符串并将其解析回来,而不是存储一个表示 flag enum 的整数。

    【讨论】:

      猜你喜欢
      • 2015-05-13
      • 2016-08-24
      • 2015-12-28
      • 2016-12-14
      • 2013-12-10
      • 2013-12-17
      • 2021-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多