title: Simplest way to use NHibernate for the official  "ASP.Net MVC 3 Getting Started"-Tutorial
body: <h1>Clarified Updated Question - Start</h1>
  <hr />
  <p>In the <a href="http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part1-cs" rel="nofollow noreferrer">official MVC 3 Getting Started-tutorial</a> it seems to me that <strong>all we have to do to get ORM working are two steps.</strong></p>
  <p><strong>First</strong> adding the simple MovieDBContext-code as described at the <a href="http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part4-cs" rel="nofollow noreferrer">end of part 4</a> ..</p>
  <pre><code>public class MovieDBContext : DbContext 
  {
      public DbSet&lt;Movie&gt; Movies { get; set; } 
  }
  </code></pre>
  <p>.. and <strong>second</strong> in the <a href="http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part5-cs" rel="nofollow noreferrer">beginning of part 5</a>, with a simple right-click on the Controllers folder we can auto-generate a MoviesController that implements CRUD()-functionality using Entity Framework by simply telling which Model to use.<br />
  <a href="http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part5-cs" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4OfCm.png" alt="&quot;Add Controller&quot;-Form" /></a>
  Now when using the web-application we can already write and read from the database.</p>
  <h1>What would be the simplest (or a simple) way to get this done for our Movie-Model with NHibernate instead of using Entity Framework?</h1>
  <hr />
  <h1>Clarified Updated Question - End</h1>
  <hr />
  <hr />
  <hr />
  <hr />
  <h1>Original question (only for additional background-info):</h1>
  <hr />
  <h3>I'm trying to create an ASP.Net MVC 3 application that uses NHibernate and Postgres.</h3>
  <h3>Background Info</h3>
  <p>Development is done on Windows with Visual Web Developer Express, the production environment will be/should be Linux+Mono.</p>
  <p>Steps that have worked so far:</p>
  <ul>
  <li>An ASP.Net Dynamic Data Entities Web Application using Npgsql and Postgres as the DB.
  Successfully run on Windows development machine.
  <a href="http://npgsql.com/index.php/2009/08/how-to-set-up-entity-framework-npgsql-part-1/" rel="nofollow noreferrer">(Following this tutorial)</a></li>
  <li>An ASP.Net MVC 3 application without using a database/model yet:
  Succesfully run on Windows development machine and deployed to Linux production environment using Mono and Nginx. (Only as a proof of concept for myself not as a web app used by the public.)</li>
  <li>An ASP.Net MVC 3 application with a model using SQL Server Express as the DB.
  Successfully run on my Windows development machine.
  <a href="http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part1-cs" rel="nofollow noreferrer">(Following the MVC 3 Getting Started-tutorial)</a></li>
  </ul>
  <h3>Question</h3>
  <p>So far I managed to get Postgres to work with a &quot;Dynamic Data Entities Web Application&quot; but with an MVC 3 Web app I'm stuck on where/how to start. For the last mentioned MVC-3-Movie-Webapp I want to switch the DB from SQL Server Express to Postgres using NHibernate and Npgsql (NHibernate since <a href="http://www.mono-project.com/Compatibility" rel="nofollow noreferrer">Mono doesn't support Entity Framework</a>).</p>
  <p>When you look at the <a href="http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part4-cs" rel="nofollow noreferrer">end of part 4</a> there's the simple MovieDBContext-code</p>
  <pre><code>public class MovieDBContext : DbContext 
  {
      public DbSet&lt;Movie&gt; Movies { get; set; } 
  }
  </code></pre>
  <p>and in the <a href="http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part5-cs" rel="nofollow noreferrer">beginning of part 5</a>, we autogenerate CRUD-stuff using Entity Framework by simply telling which Model to use.
  (MoviesController.cs, Create.cshtml, Delete.cshtml, Details.cshtml, Edit.cshtml, and Index.cshtml)</p>
  <p><strong>So I have that working with Entity Framework and SQL Server Express, but how would I achieve the same result by using NHibernate? (doesn't have to be with postgres immediately, sticking with SQL-Server as a first step would be fine)</strong> (Hopefully with similar simplicity, but getting the result itself would be great)<br />
  I found a lot of old stuff and how I would manually map things, but what would be a good-up to date standard way of achieving this with NHibernate for MVC 3?</p>
  <p>(The closest thing I found was the source code mentioned in <a href="https://stackoverflow.com/questions/4911242/nhibernate-mvc3-sample-application">this thread</a>, but it's 64 MB unzipped I got several &quot;Projects not loaded successfully&quot;-errors and the author said he uses MVC 2 so I think it's a little over my head for being a complete NHibernate noob.)</p>
  <p>I think showing how this is done could be very useful for others as well, since the original tutorial is very easy to follow and is linked as the official starting point for MVC 3 app-development on <a href="http://www.asp.net/mvc" rel="nofollow noreferrer">http://www.asp.net/mvc</a> (&quot;Your First ASP.NET MVC App&quot;).
  So I think this would be a great up to date example about how to use NHibernate with MVC 3.</p>