Entity Framework 6 Unable to retrive metadata

c# entity-framework entity-framework-6

Question

I am using EF 6 pre-3.

Product model:

namespace ProductStore.Models
{
    public class Product
    {
        [ScaffoldColumn(false)]
        public int Id { get; set; }
        [Required]
        public string Name { get; set; }
        public decimal Price { get; set; }
        public decimal ActualCost { get; set; }
    }

}

When I created a controller, I get the following error:

Unable to retrieve metadata for 'ProductStore.Models.Project'. Unable to cast object of type 'System.Data.Entity.Core.Objects.ObjectContext' to type 'System.Data.Objects.ObjectContext'.

The Context is:

namespace ProductStore.Models
{
    public class OrdersContext : DbContext
    {
        public OrdersContext()
            : base("name=OrdersContext")
        {
        }

        public DbSet<Product> Products { get; set; }
        public DbSet<Order> Orders { get; set; }
        public DbSet<OrderDetail> OrderDetails { get; set; }
    }
}

My connection string is :

<add name="OrdersContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Orders.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />

Popular Answer

Entity Framework 6 does not support scaffolding. Using NuGet package manager console to get Entity Framework 5 will fix this issue. You will then be able to create your controller with CRUD actions. Here is a link to NuGet EF5.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why