"Input string was not in a correct format" when using LINQ

c#, linq, type-conversion

Solution

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

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.

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.

Thank you all.

Problem

I am trying to do a `FirstOrDefault()` query on an Object Set and a weird exception is thrown: My Code: ``` private RecordObject GetRecordByID(int recID) { return _objectSet.FirstOrDefault(rec => rec.ID == recID); } ``` Exception Message: Input string was not in a correct format `InnerException` is null. Stack Trace: ``` 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. 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.

Original source