title: How to query a DbSet with a string 'where clause'?
body: <p>I have the following (greatly abridged) generic repository class:</p>
  
  <pre><code>public class Repository&lt;TEntity&gt; : IRepository&lt;TEntity&gt; where TEntity : class
  {
      private DbSet&lt;TEntity&gt; _entitySet;
      private NewExternalsContext _dbContect;
  
      public Repository(NewExternalsContext dbContext)
      {
          _dbContect = dbContext;
          _entitySet = _dbContect.Set&lt;TEntity&gt;();
      }
  
      public virtual TEntity Get(object objectId)
      {
          // TODO Figure out how to use 'id' to build an Expression&lt;Func&lt;TEntity, bool&gt;&gt;.
          throw new NotImplementedException();
      }
  
      public virtual TEntity FindOne(Expression&lt;Func&lt;TEntity, bool&gt;&gt; where)
      {
          return _entitySet.FirstOrDefault(where);
      }
  }
  </code></pre>
  
  <p>My problem with the <code>public virtual TEntity Get(object objectId)</code> method is that because the repository is generic, I don't know that <code>TEntity</code> has any id field, or what it is called. The best I can do is check if it has an <code>Id</code> field, my most common name for id fields. Then, how do I e.g. do say <code>_entitySet.Where("Id = " + objectId)</code>? I have the <code>public virtual TEntity FindOne(Expression&lt;Func&lt;TEntity, bool&gt;&gt; where)</code> method, but when I just want to get an object by <code>id</code>, as is so common, I don't want to write out a whole lambda expression.</p>