title: ASP.NET MVC4 Setting up DB Context and Models
body: <p>I am working with an ASP.NET MVC4 project (school project, so I am learning the framework), trying to get working entity framework 6.0 with a Code-first perspective. I created my models (<code>/Models/</code>) and the <code>DbContext</code> like this:</p>
  
  <pre><code>using System;
  using System.Data.Entity;
  using System.Data.Entity.ModelConfiguration.Conventions;
  
  namespace Autokereskedes.Models
  {
      public class AutoDb : DbContext
      {
          public DbSet&lt;Car&gt; Cars { get; set; }
          public DbSet&lt;Reservation&gt; Reservations { get; set; }
          public DbSet&lt;Depo&gt; Depos { get; set; }
          public DbSet&lt;User&gt; Users { get; set; }
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              modelBuilder.Conventions.Remove&lt;OneToManyCascadeDeleteConvention&gt;();
  
              base.OnModelCreating(modelBuilder);
          }
      }
  }
  </code></pre>
  
  <p>But when I want to use it in my controllers I get an error </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using Autokereskedes.Models;
  
  namespace Autokereskedes.Controllers
  {
      public class AccountController : Controller
      {
  </code></pre>
  
  <p>......</p>
  
  <pre><code>private bool IsUserDataValid(string email, string password)
  {
      bool r = false;
      var crypto = new SimpleCrypto.PBKDF2();
      using (var d = new AutoDb())
      {
          var user = new d.SystemUsers.FirstOrDefault( u =&gt; u.email == email);
          if (user != null &amp;&amp; user.Password == crypto.Compute(password))
          {
              r = true;
          }
      }
  
      return r;
  }
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>Error   1   The type or namespace name 'd' could not be found (are you missing a using directive or an assembly reference?) C:\_temp\stackoverflow\Autokereskedes\Controllers\AccountController.cs  64  32  Autokereskedes
  </code></pre>
  
  <p>Also, I can't really get working the models, I think I made mistakes when I coded the table relations (my tables have mostly One to Many associations), still when I used the models, I got foreign key errors (HomeController).</p>
  
  <p>My whole project accessible here: <a href="https://copy.com/KdinHUWErNMpN7pF" rel="nofollow">download</a></p>
  
  <p>Thank you for your time and help, I am quite lost here, browsing tutorials but still missing the point.</p>