简体   繁体   中英

Entity Framework 6 Unable to retrive metadata

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" />

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.

我已经测试过,Entity Framework 6还不能做脚手架。

我也进行了测试,我认为Entity FrameWork 6不稳定。您可以重建项目,使用Nuget安装Entity FrameWork 5。

Update EF to version 6.0.1 then rebuild your solution. Should work after that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM