NHibernate Linq.Where(x=>;x.Kind==(byte)criteria.Value)不起作用
fallowing使用的是NHibernate 2.1。现在有了NHibernate 3,情况就不一样了。 我有一个列为Kind的表,它有一个fallowing映射: 现在,当我试着用Linq .Where(x=>x.Kind==(字节)条件.Value) 其中criteria.Value是字节值,我得到一个InvalidCastException:(无法执行查询) [从ProjectType projecttyp0中选择…其中projecttyp0\u0.Kind=?按项目排序0\u0.Name asc] 名称:p1-值:0)--> d:\CSharp\NH\NHibernate\src\NHibernate\Type\ByteType.cs:Zeile 44中的bei-NHibernate.Type.ByteType.Set(IDbCommand cmd,对象值,Int32索引)。 d:\CSharp\NH\NHibernate\src\NHibernate\Type\NullableType.cs:Zeile 180中的bei-NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd,对象值,Int32索引)。 在d:\CSharp\NH\NHibernate\src\NHibernate\Type\NullableType.cs:Zeile 139中,bei-NHibernate.Type.NullableType.NullSafeSet(IDbCommand st,对象值,Int32索引,ISessionImplementor会话)。 在d:\CSharp\NH\NHibernate\src\NHibernate\Engine\QueryParameters.BindParameters(IDbCommand命令,Int32启动,ISessionImplementor会话)中,输入bei-NHibernate.Engine.QueryParameters.BindParameters(IDbCommand,Int32启动,ISessionImplementor会话) 我需要改变什么吗 谢谢你的帮助NHibernate Linq.Where(x=>;x.Kind==(byte)criteria.Value)不起作用,linq,nhibernate,linq-to-nhibernate,Linq,Nhibernate,Linq To Nhibernate,fallowing使用的是NHibernate 2.1。现在有了NHibernate 3,情况就不一样了。 我有一个列为Kind的表,它有一个fallowing映射: 现在,当我试着用Linq .Where(x=>x.Kind==(字节)条件.Value) 其中criteria.Value是字节值,我得到一个InvalidCastException:(无法执行查询) [从ProjectType projecttyp0中选择…其中projecttyp0\u0.Kind=?按项目排序0\u0.Na
向您问好,托马斯什么类型的标准是。值
尝试将
(byte)criteria.Value
替换为Convert.ToByte(criteria.Value)
我遇到了几乎相同的问题:System.InvalidCastException:指定的强制转换无效
我的POCO属性的类型是:byte?
我的MS SQL 2005列的类型为:tinyint NULL
每次我在属性上使用LINQ to NHibernate进行查询时,都会抛出System.InvalidCastException。标准API工作正常
我最终提交了一个bug w/NH项目
显然,MS LINQ代码中有一个bug,将字节转换为int
我的解决方法是在我的POCO属性上使用类型(int?),但保留TINYINT作为数据库类型
在您的示例中,criteria.Value将是int类型而不是byte。这将避免MS LINQ错误 由@raulg提交的bug是。我今天在版本3.2中遇到了这个问题,并确认升级到3.3解决了这个问题。Hi Diego-criteria。值的类型为byte。我还尝试了Convert.ToByte(criteria.Value)。它也不起作用。