title: Select specific columns in a generic repository function
body: <p>We want to create a generic function which will select only required columns rather than returning the whole entity. For example I have a Country class which 
  has the following properties.</p>
  
  <pre><code>[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  public int CountryId { get; set; }
  [Required]
  public string Name { get; set; }
  public int CreatedBy {get;set;}
  public DateTime CreatedDate {get;set;}
  </code></pre>
  
  <p>And I have a Respiratory Class which is common for all entities.</p>
  
  <pre><code>public class Repository&lt;T&gt; : IRepository&lt;T&gt; where T : class
  {
      DbContext db;
      DbSet&lt;T&gt; currentEntity;
      public Repository(DbContext db)
      {
          this.db = db;
          currentEntity = db.Set&lt;T&gt;();
      }
      public void Add(T TEntity)
      {
          currentEntity.Add(TEntity);
      } 
  
  
      public virtual List&lt;T&gt; GetAll()
      {
          return currentEntity.ToList&lt;T&gt;();
      }
  }
  </code></pre>
  
  <p>As <code>GetAll</code> method is returning all columns, but I want to select only <code>Name</code> and <code>CountryId</code>. How can I create a generic function which would be returning only required data?</p>