I have a very big table with more then one million rows.
Simple:
public partial class Country
{
public Country()
{
this.Streets = new HashSet<Streets>();
}
public int Id { get; set; }
public virtual ICollection<Street> Streets { get; set; }
}
public partial class Street
{
public int Id { get; set; }
public int CountryId { get; set; }
public virtual Country Country { get; set; }
}
If I want to get the total count of streets in a country I can do
context.CountryStreets.Count(v=>v.CountryId == X)
EF gives you an easy method to access the related table with lazy loading:
Country.Streets.Count()
This method is very nice and easy but... For some reason it's loading the total related table.
Why? And how can I change this behavior?
Thanks In Advance