【发布时间】:2011-04-06 18:49:41
【问题描述】:
我正在使用 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
【问题讨论】:
标签: asp.net linq linq-to-entities primitive-types