Why Entity Framework does not create the right query?

Good day!

Is the substance
public partial class countries
{
 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
 public countries()
{
 this.people = new HashSet<people>();
}

 public int id { get; set; }
 public string full_name { get; set; }
 public string name { get; set; }
 public string full_name_eng { get; set; }
 public string name_eng { get; set; }
 public string iso_num { get; set; }
 public string iso2 { get; set; }
 public string iso3 { get; set; }

 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadonly")]
 public virtual ICollection<people> people { get; set; }
 }</people></people>


The repository has made the
public countries FindFirst(Func<countries, bool> predicate)
{
 return db.countries.FirstOrDefault(predicate);
 }</countries,>


Call the method from code
public bool CountryExist(int iso)
{
 var result = db.Countries.FindFirst(c=>c.iso_num == iso.ToString());
 return result != null ? true : false;
 }


Why EF creates a query without the imposition of the WHERE clause?
SELECT * FROM countries
July 8th 19 at 15:52
1 answer
July 8th 19 at 15:54
Solution
Read about the difference between IEnumerable<> and IQuerable<>
public countries FindFirst(Expression<func<countries, bool>> predicate)
{
... 
}</func<countries,>


CountryExist() better to rewrite like this:
public bool CountryExist(int iso)
{
 var isoNum = iso.ToString();
 return db.Countries.Any(c=>c.iso_num == isoNum);
}

Find more questions by tags C#Entity Framework