我正在使用 EF 6 pre-3。
产品型号:
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; }
}
}
创建控制器时,出现以下错误:
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'.
上下文是:
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; }
}
}
我的连接字符串是:
<add name="OrdersContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Orders.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />