title: Generic Repository Pattern in Entity Framework
body: <p>I am new to Generic Repository pattern. I tried to create a sample to add, update, delete, and find method using generic repository. Find my sample code,</p>
  
  <p>Generic Repository Interface and class:</p>
  
  <pre><code>public interface IRepository&lt;T&gt; : IDisposable where T : class
  {        
      IEnumerable&lt;T&gt; Find(Func&lt;T, bool&gt; predicate);
      void Add(T entity);
      void SaveChanges();
  }
  
  public class DataRepository&lt;T&gt; : IRepository&lt;T&gt; where T : class
  {
      private ObjectContext _context;
      private IObjectSet&lt;T&gt; _objectSet;
  
      public DataRepository(ObjectContext context)
      {
         _context = context;
         _objectSet = _context.CreateObjectSet&lt;T&gt;();
      }
      public IEnumerable&lt;T&gt; Find(Func&lt;T, bool&gt; predicate)
      {
          return _objectSet.Where(predicate);
      }
      public void Add(T entity)
      {
         _objectSet.AddObject(entity);
      }
  }
  </code></pre>
  
  <p>And i used this method like below,</p>
  
  <pre><code>DataRepository&lt;tblUser&gt; _tblUser = new DataRepository&lt;tblUser&gt;(new SampleRepositoryEntities());
  DataRepository&lt;TestingTable&gt; sampleRepository = new DataRepository&lt;TestingTable&gt;(new SampleRepositoryEntities());
  public void GetRecords()
  {
      var record1 = sampleRepository.Find(f =&gt; f.id == 1).FirstOrDefault();
      var record = _tblUser.Find(f =&gt; f.emailid == "karthik@abc.com").FirstOrDefault();
  }
  </code></pre>
  
  <p>i can find the records using Find method from the table "TestingTable" in  SampleRepositoryEntities. Because this table has very less record around 10 records.</p>
  
  <p>But i tried to find first record that match the email id from tbluser table, this table has more than 50,000 records, i couldn't get the result keep loading at this point and haven't got any exception also. What i did wrong.. Can anyone please let me clear this?</p>