Cannot create controller with Entity framework - Unable to retrieve metadata

c# entity-framework visual-studio-2013


I'm using VS2013

When I try to create an "MVC 5 Controller with views using entity Framework" I get the following error:

there was an error running the selected code generator ''Unable to retrieve metadata for WebApplication.Domain.Entities.Product'.'


using System.Data.Entity;
using WebApplication.Domain.Entities;

namespace WebApplication.Domain.Concrete
    public class EFDbContext : DbContext
        public DbSet<Product> Products;


using System.ComponentModel.DataAnnotations;

namespace WebApplication.Domain.Entities
    public class Product
        public int ProductID { get; set; }

        public string Title { get; set; }


<?xml version="1.0" encoding="utf-8"?>
  For more information on how to configure your ASP.NET application, please visit
    <!-- For more information on Entity Framework configuration, visit -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <add name="EFDbContext" connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=WebApplication;Integrated Security=True" providerName="System.Data.SqlClient"/>
    <add key="webpages:Version" value="" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />

I have a Table set up called Products and it has a definition like so:

CREATE TABLE [dbo].[Products] (
    [ProductID] INT            IDENTITY (1, 1) NOT NULL,
    [Title]     NVARCHAR (255) NULL,

Any ideas what is going wrong? I have tried everything that has returned on Google.

Packages I have installed:

<?xml version="1.0" encoding="utf-8"?>
  <package id="EntityFramework" version="6.0.1" targetFramework="net45" />
  <package id="jQuery" version="1.10.2" targetFramework="net45" />
  <package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Web.Infrastructure" version="" targetFramework="net45" />
  <package id="Unity" version="3.0.1304.1" targetFramework="net45" />
  <package id="Unity.Mvc" version="3.0.1304.0" targetFramework="net45" />
  <package id="WebActivatorEx" version="2.0.4" targetFramework="net45" />

My project can be found here:

12/9/2013 10:49:14 PM

Accepted Answer

public class EFDbContext : DbContext
    public DbSet<Product> Products { get; set; }

Forgot the { get; set; }... all works now #crying

12/10/2013 12:02:59 AM

Popular Answer

Problem may be because of missing [NotMapped] Attribute in one of the model class.

As I missed the attribute and I was cunning my head.

public HttpPostedFileBase Logo { set; get; }

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow