I have this small model:
class User
{
public int Id { get; set; }
public Community { get; set; }
}
class Community
{
public int Id { get; set; }
public Country { get; set; }
}
class Country
{
public int Id { get; set; }
public string Name { get; set; }
}
The DbContext is this:
public class SmallDbContext : DbContext
{
public DbSet<User> Users { get; set; }
}
I would like to create query that will retrieve the Users
of a given Country
My bet using is this:
int countryId = 2:
var usersOfAGivenCountry = dbContext.Users
.Where(community => community.Country.Id == countryId);
But I'm not sure if I'm doing it right. Is this correct way to do it?
Also, I wonder how this will handle a null Community
in a User
.