Azure 检测到类型不兼容的二进制运算符。找到操作数类型';Edm.Int32';和';Edm.Int32';对于操作员类型';和';

Azure 检测到类型不兼容的二进制运算符。找到操作数类型';Edm.Int32';和';Edm.Int32';对于操作员类型';和';,azure,tsql,xamarin,azure-sql-database,azure-mobile-services,Azure,Tsql,Xamarin,Azure Sql Database,Azure Mobile Services,当我通过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,OriginalSl

当我通过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)
f.TypesDb
types
都是C#code中的int。(注意:
f.TypesDb
通过json序列化映射到
Types


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

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

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

作为一种肮脏的解决方法,我现在在数据库中存储一个逗号分隔的
int
s字符串,并将其解析回来,而不是存储一个表示
标志枚举的整数

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