title: How to write a generic where for several types in linq to entities?
body: <p>I have a lot of classes</p>
  
  <pre><code>public class City
  {
      public int CityID { get; set; }
      public string Name { get; set; }
      public string Comment { get; set; }
      public virtual ICollection&lt;ApplicationUser&gt; DryCleanings { get; set; }
      public DateTime DateCreated { get; set; }
      public DateTime DateChanged { get; set; }
      public bool IsDeleted { get; set; }
  }
  
      public class Marker
  {
      public int MarkerID { get; set; }
      public string Name { get; set; }
      public string Comment { get; set; }
      public byte[] Icon { get; set; }
      public virtual IEnumerable&lt;ApplicationUser&gt; Cleanings { get; set; }
      public DateTime DateCreated { get; set; }
      public DateTime DateChanged { get; set; }
      public bool IsDeleted { get; set; }
  }
  .
  .
  .
  </code></pre>
  
  <p>They all have the same three properties</p>
  
  <pre><code>    public DateTime DateCreated { get; set; }
      public DateTime DateChanged { get; set; }
      public bool IsDeleted { get; set; }
  </code></pre>
  
  <p>I need to write same where query for each of them, something like this</p>
  
  <pre><code>_db.Cities.Where(c =&gt; !c.IsDeleted &amp;&amp; c.DateChanged &gt; oldDate &amp;&amp; c.DateChanged &lt; oldDate);
  _db.Markers.Where(m =&gt; !m.IsDeleted &amp;&amp; m.DateChanged &gt; oldDate &amp;&amp; m.DateChanged &lt; oldDate);
  </code></pre>
  
  <p>i do not want write this query for every class. Can i write this predicate once and use for all?</p>
  
  <p>ps. I tried inherited from Interface </p>
  
  <pre><code>    public interface IDate
  {
      public DateTime DateCreated { get; set; }
      public DateTime DateChanged { get; set; }
      public bool IsDeleted { get; set; }
  }
  </code></pre>
  
  <p>and write something like this</p>
  
  <pre><code> Expression&lt;Func&lt;IDate, bool&gt;&gt; lessOldDate = c =&gt; !c.IsDeleted &amp;&amp; c.DateChanged &gt; oldDate &amp;&amp; c.DateChanged &lt; oldDate;
  </code></pre>
  
  <p>but i getting type IDate however i need Marker</p>
  
  <p><img src="https://i.stack.imgur.com/UjTGs.png" alt="enter image description here"></p>