title: Entity Framework Code-First Aproach and ModelValidationException
body: <p>I'm building an MVC application and trying to use code-first aproach while building entities and database.</p>
  
  <p>I get <code>ModelValidationException</code> when I run code. (Message: <strong>System.Data.Entity.ModelConfiguration.ModelValidationException' occurred in EntityFramework.dll but was not handled in user code</strong>)</p>
  
  <p>This is code:</p>
  
  <p><strong>Controller</strong>:</p>
  
  <pre><code>public class HomeController : Controller {
      PhonesDB _db = new PhonesDB();
  
      public ActionResult Index() {
          var model = from b in _db.ProductList //Exception appears here
                      select b;
          return View(model);
      }
  }
  </code></pre>
  
  <p><strong>Models</strong>:</p>
  
  <pre><code>namespace SmartPhoneCatalog.Models {
      public class Products {
          public int ProductID { get; set; }
          public string Manufacturer { get; set; }
          public string Name { get; set; }
          //...
      }
  }
  
  namespace SmartPhoneCatalog.Models {
      public class PhonesDB:DbContext {
          public DbSet&lt;Products&gt; ProductList { get; set; }
      }
  }
  </code></pre>
  
  <p>and this is the <strong>view</strong>:</p>
  
  <pre><code>@model IEnumerable&lt;SmartPhoneCatalog.Models.Products&gt;
  
  @{
      ViewBag.Title = "Home";
  }
  
  @foreach (var item in Model) {
      &lt;div&gt;
          &lt;h4&gt;@item.Name&lt;/h4&gt;
          &lt;div&gt;@item.Price&lt;/div&gt;
          &lt;hr/&gt;
      &lt;/div&gt;
  }
  </code></pre>
  
  <p>Am I missing something?</p>
  
  <p>Tried starting empty mvc application and then template but had the same problem on both one.</p>
  
  <p>Replacing LINQ with <code>var model = _db.ProductList.ToList();</code> didn't help. Also tried editing <code>PhonesDB</code> model(changes are in <strong>bold</strong>):</p>
  
  <pre><code>public **partial** class PhonesDB : DbContext {
      public PhonesDB():**base("PhonesDB")**{
      }
  
      **protected override void OnModelCreating(DbModelBuilder modelBuilder) {
          modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
      }**
  
      public DbSet&lt;Products&gt; ProductList { get; set; }
  }
  </code></pre>
  
  <p>still getting same exception.
  Any ideas how to fix it?</p>