最近、ASP.NET MVC と Entity Framework を使い始めました。
既存のデータベースを使用して、クラスをデータベース テーブルにマップしようとしました。成功せずに。
私のデータベーステーブルをお見せしましょう:
->カテゴリ --> ID (PK) --> タイトル --> 説明
->製品 --> ID (PK) --> 名前 --> 説明 --> 価格 --> カテゴリ (FK -> カテゴリツリー)
-> CategoriyTree --> Id (PK) --> ParentCategory (FK -> カテゴリ) --> ChildCategory (FK -> カテゴリ)
さて、Entity Framework のクラス:
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 Migrations を使用してデータベースを更新することを検討してください ( http://go.microsoft.com/fwlink/?LinkId=238269 )。
誰かがこれを理解するのを手伝ってくれることを願っています;-)
よろしくお願いします