That's not
Where
that causes the problem!
You have declared
student
as a
Students
variable:
Students student = new Students();
But your code converts the entire return collection to a string:
db.Students.Where(x => x.UserId == userId).ToString()
and tries to assign that string to the
student
!
The first thing you need to so is think about what you want to return - and
Where
returns a collection of items, not a single item. INstead of where, I'd suggest
FirstOrDefault[
^]:
student = db.Students.FirstOrDefault(x => x.UserId == userId);
Which returns a single value (or null if there are no matches)
This assumes that
db.Students
is a collection of
Student
items!