无法将类型“System.Int32”强制转换为“System.Object”类型。 LINQ to Entities仅支持转换实体数据模型基元类型

我正在使用LINQ to Entities,我在运行时收到以下错误。 “无法将类型'System.Int32'强制转换为'System.Object'.LINQ to Entities仅支持转换实体数据模型基元类型”。 LINQ语句如下所示:
(From item In _EntityObject.SystemUsers
 Where item.Username = UsernameValue And
     Not Equals(item.ID, IDValue)
 Select item.Active).Count
当IDValue设置为Nothing时,查询执行完美,而当我将值设置为Integer时,我收到上述错误。 item.ID是Integer类型的属性,而IDValue的类型是Nullable(Of Integer)。 我有相同的LINQ查询,我在其他地方使用的不同字段完美地工作。
(From item In _EntityObject.Languages
 Where item.Reference = Reference And
     Not Equals(item.ID, ID)
 Select item.Name).Count
    
已邀请:
只需使用
=
标志
(From item In _EntityObject.SystemUsers
 Where item.Username = UsernameValue And
     Not (item.ID = IDValue)
 Select item.Active).Count
    
问题通过以下声明解决:
(From item In _EntityObject.SystemUsers Where 
item.Username = Username And (Not (item.ID = IDValue)
 Or IDValue Is Nothing) Select item.Name).Count)
    

要回复问题请先登录注册