我最近开始使用 ASP.NET MVC 和实体框架。
使用现有数据库,我尝试将我的类映射到数据库表。没有成功。
让我向您展示我的数据库表:
->类别 --> Id (PK)--> 标题--> 描述
->产品 --> Id (PK) --> 名称 --> 描述 --> 价格 --> 类别 (FK -> CategoryTree)
->分类 树 --> Id (PK) --> ParentCategory (FK -> Category) --> ChildCategory (FK -> Category)
现在,我的实体框架类:
class Products
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal? Price { get; set; }
public virtual ICollection<CategoryTree> Category { get; set; }
}
class Categories
{
public int categoriesId { get; set; }
public string Title { get; set; }
public string Description { get; set; }
}
class CategoryTree
{
public int Id { get; set; }
public virtual ICollection<Categories> ParentCategory { get; set; }
public virtual ICollection<Categories> ChildCategory { get; set; }
}
class EFDbContext : DbContext
{
public DbSet<Products> Products { get; set; }
public DbSet<Categories> Categories { get; set; }
public DbSet<CategoryTree> CategoryTree { get; set; }
}
如果我启动应用程序,编译器会提示以下错误消息: 支持“EFDbContext”上下文的模型自创建数据库以来已更改。考虑使用 Code First 迁移来更新数据库 ( http://go.microsoft.com/fwlink/?LinkId=238269 )。
我希望有人可以帮助我理解这一点;-)
此致