title: C# linq query filter child Collection
body: <p>Good day,</p>
  
  <p>I have a model class like below</p>
  
  <pre><code>    public class EmployeeModel
      {
        [Key]
       public int employeeId{get;set;}
       public string Fullname {get;set;}
       public string Address{get;set;}
       public ICollection&lt;PaymentModel&gt; Payments {get;set;}
      }
  
  
      public class PaymentModel
      {
  
        [Key]
       public int PaymentId{get; set;}
       public int employeeId{get; set;}
       public decimal PaymentAmount{get; set;}
        public int IsPosted {get; set;}
        public virtual EmployeeModel Employee {get; set;}
  
      }
  </code></pre>
  
  <p>i just want to query the list of employee together with their list of payments using linq. so i code like this:</p>
  
  <pre><code>dbcontext db = new dbcontext();
  var listing = from d in db.Employees
                .include("Payments")
                 select d;
  </code></pre>
  
  <p>this listing show the all of the employee and all its payments.
  but i need to filter each employee Payments that IsPosted = 1</p>
  
  <p>so as initial answer, ill do this code;</p>
  
  <pre><code>dbcontext db = new dbcontext();
  List&lt;EmployeeModel&gt; FinalList = new List&lt;EmployeeModel&gt;();
  var listingofEmp = db.employee.ToList();
  
  foreach(EmployeeModel emp in listingofEmp){
  emp.Payments= db.payments.where(x =&gt; x.IsPosted == 1).ToList();
  FinalList.Add(emp);
  }
  </code></pre>
  
  <p>my Question is, is ther any other way to code it much easier? something like this.</p>
  
  <pre><code>    dbcontext db = new dbcontext();
      var listing = from d in db.Employees
                    .include(d =&gt; x.Payments.IsPosted == 1)
                     select d;
  </code></pre>
  
  <p>im curently using entityframework 5</p>
  
  <p>ive research regarding it not work for me <a href="https://www.google.com.ph/search?sourceid=chrome-psyapi2&amp;ion=1&amp;espv=2&amp;ie=UTF-8&amp;q=how%20to%20filter%20child%20collections%20in%20linq&amp;oq=how%20to%20filter%20child%20collec&amp;aqs=chrome.1.69i57j0j69i60l2.8926j0j7" rel="nofollow">Link</a></p>
  
  <p>Hope someone will help me </p>
  
  <p>Thanks In Advance Guys</p>