检测到具有不兼容类型的二元运算符。找到操作数类型'Edm.Int32'和'Edm.Int32'用于运算符类'And'

问题描述 投票:0回答:1

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

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'."

但是直接查询DB时

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个回答
1
投票

IMobileServiceClient将代码中的&错误地转换为URL过滤器参数中的andand被解释为逻辑,因此类型Edm.Int32与此不相容。

无法使用URL中的按位和过滤器参数。

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

© www.soinside.com 2019 - 2024. All rights reserved.