Reputation: 528
I have this class :
public class Person
{
public int Id { get; set; }
public string UserName { get; set; }
public int GroupId { get; set; }
}
How do I do if I want to return GroupId
if I have given Id
.. like
public Person GetGroupId (int id)
{
return _context.Person.Where(c => c.Id == id)
.Select(x => x.GroupId)
.FirstOrDefault();
}
But this giving me error message like "cannot implicitly convert type".
Upvotes: 0
Views: 58
Reputation: 247323
The type returned by the query does not match the return type defined by the method.
Update the method to return the desired type, which in this case is int
public int GetGroupId (int id) {
return _context.Person.Where(c => c.Id == id).Select(x => x.GroupId).FirstOrDefault();
}
Upvotes: 3