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



当我通过移动应用程序通过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 文档中,声明按位和运算符对两个整数(32 位类型(有效。OData Doc 指出,EDM。Int32 表示有符号的 32 位整数值。

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

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

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

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

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

无法在 URL 的筛选器参数中使用按位和

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

相关内容

最新更新