"输入字符串的不正确的格式"使用LINQ时, [英] "Input string was not in a correct format" when using LINQ

查看:1348
本文介绍了"输入字符串的不正确的格式"使用LINQ时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个对象集和一个奇怪的异常的 FirstOrDefault()查询被抛出:

I am trying to do a FirstOrDefault() query on an Object Set and a weird exception is thrown:

我的代码:

private RecordObject GetRecordByID(int recID)
{
    return _objectSet.FirstOrDefault(rec => rec.ID == recID);
}



异常消息:

输入字符串的不正确的格式

Input string was not in a correct format

<$ C 。$ C>的InnerException 为空

堆栈跟踪:

at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&         number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Convert.ToDecimal(String value, IFormatProvider provider)
at System.String.System.IConvertible.ToDecimal(IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at Oracle.DataAccess.Client.OracleDataReader.ChangeType(Object sourceValue, Type targetType)
at Oracle.DataAccess.Client.OracleDataReader.GetValue(Int32 i)
at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
at System.Data.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String typeName)
at lambda_method(Closure , Shaper )
at System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
at lambda_method(Closure , Shaper )
at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()

奇怪的是,我没有做任何类型转换。

The weird thing is that I'm not doing any type conversions.

PS:的数据库是Oracle 10g中,但因为我使用EF,我想这并不重要,但为了以防万一,你需要这个细节

P.S: The database is Oracle 10g, but since I'm using EF, I guess this does not matter but just in case you need this detail.

推荐答案

好吧,我整理了这一点,我将保持这个问题,万一有人有同样的问题。

Ok, I've sorted this out and I will keep this question in case someone has the same problem.

要解决这个问题,我需要从数据库中重新导入我的表,显然,有我的ADO.Net对象和数据库之间不兼容的一些列(S)。

To solve it, I needed to re-import my tables from the database, apparently, there was some incompatible column(s) between my ADO.Net objects and the database.

我想,EF试图让一个演员的操作,以弥补我的错误(暂且不兼容的版本),和演员是不可能的,而这正是该类型转换来的。

I think, EF was trying to make a Cast operation to compensate for my mistake (leaving non-compatible versions), and the cast is not possible, and this is where the type-conversion came from.

感谢大家。

这篇关于&QUOT;输入字符串的不正确的格式&QUOT;使用LINQ时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆