{ public class Category { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } [Required] [DisplayName("Category")] public string Name { get; set; } public virtual IList<SubCategory> SubCategory { get; set; } }
} public class SubCategory { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } [Required] [DisplayName("Subcategory")] public string Name { get; set; } [DisplayName("Category")] public Guid CategoryId { get; set; } [ForeignKey("CategoryId")] public virtual Category Category { get; set; } public virtual IList<Product> Products { get; set; } } public class Product { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ProductId{ get; set; } public string ProductNumber { get; set; } public string Name{ get; set; } public string Description { get; set; } public double Price { get; set; } public int Stock{ get; set; } public bool IsApproved { get; set; } public bool IsHome { get; set; } public DateTime CreatedDate{ get; set; } public List<ProductImage> ProductImages { get; set; } [DisplayName("Subcategory")] public Guid SubCategoryId { get; set; } [ForeignKey("SubCategoryId")] public virtual SubCategory SubCategories { get; set; } } } DBContext : public DbSet<Product> Products { get; set; } public DbSet<ProductFavorite> ProductFavorites{ get; set; } public DbSet<ProductImage> ProductImages { get; set; } public DbSet<Category> Categories { get; set; } public DbSet<SubCategory> SubCategories { get; set; } public DbSet<Member> Members { get; set; } public DbSet<User> Users { get; set; } public DbSet<Blog> Blogs { get; set; } Migrations ile dbyi update etmeye çalıştığımda aşağıdaki hatayı alıyorum. Yardımcı olur musunuz ? Foreign key 'FK_Products_Categories_CategoryId' references invalid table 'Categories'. Could not create constraint. See previous errors. |
Bildirim