LINQ Query Error : how can I precisely identify which field is causing this error?

Viewed 512

When this error happens in the LINQ Query, how can I precisely identify which field is causing error ?

MethodName : get_Int32. Error : System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Int32'. at Microsoft.Data.SqlClient.SqlBuffer.get_Int32() at lambda_method(Closure , QueryContext , DbDataReader , ResultContext , Int32[] , ResultCoordinator ) at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.QueryingEnumerable1.Enumerator.MoveNext() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source) at ..

My LINQ Query is pretty simple.

return dbContext.SomeTable.Where(x => x.KeyValue == keyValue).FirstOrDefault();

Here is the "real trouble". My table has 300+ fields.

It will be nice if there is an elegant solution to precisely identify the column that is causing this error. Please advise.

0 Answers
Related