1
不工作
在實體框架6 dosent播種我的實現代碼似乎與核心的EntityFramework兼容播種數據庫imlementation在EntityFrameworkcore
這裏是我的代碼
public class CustomerOrderSeedData : DropCreateDatabaseIfModelChanges<CustomerOrderEntities>
{
protected override void Seed(CustomerOrderEntities context)
{
GetOrderDetails().ForEach(od => context.OrdersDetails.Add(od));
context.Commit();
}
private static List<OrdersDetails> GetOrderDetails()
{
return new List<OrdersDetails>
{
new OrdersDetails {
OrderId = 1,
ProductId = 1,
Quantity = 10,
UnitPrice = 12,
Discount = 3
},
new OrdersDetails {
OrderId = 1,
ProductId = 2,
Quantity = 3,
UnitPrice = 4,
Discount = 2
}
}
}
EntityFrameworkCore似乎並不喜歡DropCreateDatabaseIfModelChanges關鍵字。有人告訴我一個如何使用EntityFrameworkcore完成播種的例子。