Search code examples
c#linqanonymous-methods

Cast Exception in C# Where clause


It's been a while since I am trying to figure out what is causing a cast exception in this case. Following is my code.

var ratingTermDetails = dtRating.AsEnumerable()
    .Where(data => data.Field<int>("RATINGID") == ratingId)
    .FirstOrDefault();

dtRating is a datatable which gets populated from the database (oracle). The datatype of the column Ratingid is Integer in the database and the column is not nullable. The variable ratingId is an integer too.


Solution

  • As @MarcGravell said, the variable was getting converted into System.Decimal in C#. Upon changing to my code worked.