title: Desing patterns with using EntityFramework?
body: <p>Interface</p>
  
  <pre><code>public interface IDinnerRepository 
  {
      IQueryable&lt;Dinner&gt; FindAllDinners();
      IQueryable&lt;Dinner&gt; FindDinnersByText(string q);
  
      Dinner GetDinner(int id);
  
      void Add(Dinner dinner);
      void Delete(Dinner dinner);
  
      void Save();
  }
  </code></pre>
  
  <p>Class that is inherited from above interface</p>
  
  <pre><code>public class DinnerRepository : NerdDinner.Models.IDinnerRepository
  {
      NerdDinnerEntities db = new NerdDinnerEntities();
  
      Public IQueryable&lt;Dinner&gt; FindDinnersByText(string q)
      {
           return db.Dinners.Where(d =&gt; d.Title.Contains(q)
               || d.Description.Contains(q)
               || d.HostedBy.Contains(q));
      }
  
      public IQueryable&lt;Dinner&gt; FindAllDinners()
      {
           return db.Dinners;
      }
  
      public Dinner GetDinner(int id)
      {
          return db.Dinners.SingleOrDefault(d =&gt; d.DinnerID == id);
      }
  
      public void Add(Dinner dinner)
      {
          db.Dinners.AddObject(dinner);
      }
  
      public void Delete(Dinner dinner)
      {
          foreach (RSVP rsvp in dinner.RSVPs.ToList())
              db.RSVPs.DeleteObject(rsvp);
  
          db.Dinners.DeleteObject(dinner);
     }
  
     public void Save()
     {
          db.SaveChanges();
     }
  }
  </code></pre>
  
  <p>Usage in a program</p>
  
  <pre><code>public class DinnerOperation
  {
      DinnerRepository dr = new DinnerRepository();
  
      // insert
      public void InsertDinner()
      {
          Dinner dinner = dr.GetDinner(5);
          dr.Dinner.Add(dinner);
          dr.Save();
      }
  
      // delete
      public void DeleteDinner()
      {
          Dinner dinner = dr.GetDinner(5);
          dr.Dinner.Delete(dinner);
          dr.Save();
      }
  }
  </code></pre>
  
  <p>And without using repository design pattern...</p>
  
  <pre><code>public class DinnerOperation
  {
      DinnerEntities entity = new DinnerEntities();
  
      // insert
      public void InsertDinner()
      {
          Dinner dinner = entity.Dinners.Find(5);
          entity.Dinner.Add(dinner);
          entity.SaveChanges();
      }
  
      // delete
      public void DeleteDinner()
      {
          Dinner dinner = entity.Dinners.Find(5);
          entity.Dinner.Remove(dinner);
          entity.SaveChanges();
      }
  }
  </code></pre>
  
  <p>Question</p>
  
  <p>I cant understand, in here, Why did we use design pattern?
  When using the Repository design pattern with Entity Framework in this way does not mean anything. </p>
  
  <p>How can I use design pattern with entitiy framework? When does it make sense to use design pattern with entity framework?</p>