[英]I cannot update entity
類別表;
public int CategoryId{ get; set; }
public string Name{ get; set; }
public List<ProductCategory> ProductCategories { get; set; }
我在表中添加了新字段;
public int CategoryId{ get; set; }
public string Name{ get; set; }
public List<ProductCategory> ProductCategories { get; set; }
public string Url{ get; set; }
更新實體時出現以下錯誤; Microsoft.EntityFrameworkCore.DbUpdateException: '更新條目時出錯。 有關詳細信息,請參閱內部異常。
eShopContext;
public DbSet<Product> Products{ get; set; }
public DbSet<Category> Categories{ get; set; }
public object Configuration { get; internal set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(
@"Server=gdagad;Database=eStoreAppDB;Trusted_Connection=True;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ProductCategory>()
.HasKey(c => new {c.CategoryId, c.ProductId});
}
}
種子數據庫.cs;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.