I am currently creating a web api in .net CORE with Entity Framework.
Whenever I try to select a single record by ID with linq, I get the following error:
An exception of type 'System.InvalidCastException' occurred in Microsoft.EntityFrameworkCore.dll but was not handled in user code.
Additional information: Unable to cast object of type 'System.Int32' to type 'System.Char'.
This error happens whenever I execute the following linq query:
int id = 1;
User user = context.Users.First(i => i.UserId == id);
I have already checked, and both field UserId
and variable id
are integers. Also the table contains enough elements and a row with an id
of 1 exists.
Can anybody tell me what I'm doing wrong here?
EDIT: Here is a part of the User
Model:
public class User
{
public int UserId { get; set; }
(...)
}
char
that's an integer in the database.