title: Repository method to find an entity with a non-Primary Key value
body: <p>So I'm not sure if I got the terminology in the title correct, but I should be able to describe what I'm trying to do.</p>
  
  <p>I have a "GenericRepository" class that all of my actual Repository classes inherit from and it contains several generic methods. The code for that class is below</p>
  
  <pre><code>public class GenericRepository&lt;TEntity&gt; where TEntity : class
  {
      internal ReportsDirectoryEntities context;
      internal DbSet&lt;TEntity&gt; dbSet;
  
      public GenericRepository(ReportsDirectoryEntities context)
      {
          this.context = context;
          this.dbSet = context.Set&lt;TEntity&gt;();
      }
  
      /////////////////////////////////////////////////////////////////////
  
      public virtual IEnumerable&lt;TEntity&gt; GetAll()
      {
          return dbSet.ToList();
      }
      public virtual TEntity GetByID(int id)
      {
          return dbSet.Find(id);
      }
      public virtual void Insert(TEntity entity)
      {
          dbSet.Add(entity);
      }
      public virtual void Delete(object id)
      {
          TEntity entityToDelete = dbSet.Find(id);
          Delete(entityToDelete);
      }
      public virtual void Delete(TEntity entityToDelete)
      {
          if (context.Entry(entityToDelete).State == System.Data.EntityState.Detached)
          {
              dbSet.Attach(entityToDelete);
          }
          dbSet.Remove(entityToDelete);
      }
      public virtual void Update(TEntity entityToUpdate)
      {
          dbSet.Attach(entityToUpdate);
          context.Entry(entityToUpdate).State = System.Data.EntityState.Modified;
      }
  }
  </code></pre>
  
  <p>Now all of that works great, what I'm trying to do now is add a GetByName method where I can pass in the "Name" property of an entity and it returns it.</p>
  
  <p>I've tried</p>
  
  <pre><code>    public virtual TEntity GetByName(string name)
      {
          return (from e in context.Set&lt;TEntity&gt;()
                  where e.Name == name
                  select e).SingleOrDefault();
      } 
  </code></pre>
  
  <p>but that underlines Name saying that "TEntity does not contain a defintion for name" so on and so forth, which makes sense.</p>
  
  <p>I can easily do this in the individual repositories but was wondering if there was a way I could do it in the Generic one.</p>
  
  <p>Any help is greatly appreciated!</p>