title: Persistence with EntityFramework in ASP.NET MVC application
body: <p>In my ASP.NET MVC application I need to implement persistence of data. I've choose Entity Framework for its ability to create classes, database tables and queries from entity model so that I don't have to write SQL table creation or Linq to SQL queries by hand. So <strong>simplicity is my goal</strong>.</p>
  
  <p>My approach was to create model and than a custom <code>HttpModule</code> that gets called at the and of each request and that just called <code>SaveChanges()</code> on the context. That made my life very hard - entity framework kept throwing very strange exception. Sometimes it worked - no exception but sometimes it did not. First I was trying to fix the problems one by one but when I got another one I realized  that my general approach is probably wrong.</p>
  
  <p>So that is the general practice to implement for implementing persistence in ASP.NET MVC application ? Do I just call <code>saveChanges</code> after each change ? Isn't that little inefficient ? And I don't know how to do that with Services patter anyway (services work with entities so I'd have to pass context instance to them so that they could save changes if they make some).</p>
  
  <p>Some links to study materials or tutorials are also appreciated. </p>
  
  <hr>
  
  <p><em>Note: this question asks for programing practice. I ask those who will consider it vague to bear in mind that it is still solving my very particular problem and right technique will save me a lot of technical problems before voting to close.</em></p>