在Entity Framework Code First方法中实现迁移?

时间:2018-02-06 19:10:42

标签: asp.net-mvc entity-framework ef-migrations

我只是尝试在实体框架代码中首先启用迁移方法。我正在开发AirlineManagementSystem。

我创建了一个类Plane。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;

namespace AirlineticketSystem.Models
{
    public class Plane
    {
        [Key]
        public int Plane_id { get; set; }
        public string Plane_Name { get; set; }
        public string Plane_No { get; set; }
        public string Plane_BClass { get; set; }
        public string Plane_EClass { get; set; }

        public List<User> Users { get; set; }
    }
}

现在我已经创建了一个用户类

using System.ComponentModel.DataAnnotations;

namespace AirlineticketSystem.Models
{
  public class User { 

    public int userid { get; set; }
    public string user_name { get; set; }
    public string user_fname { get; set; }
    public string usercnic { get; set; }
    public string user_passport { get; set; }
    public string user_bloodGp { get; set; }
    public string user_nationality { get; set; }
    public string usertype { get; set; }
    public string status { get; set; }
    public int mobilenumber { get; set; }
    public string gender { get; set; }

   public int Plane_id { get; set; }
   public Plane Plane { get; set; }
    }

}

所以One Plane可以有很多用户。

请告诉我如何在Package Manage Console中启用迁移?

1 个答案:

答案 0 :(得分:0)

您可以按照以下说明操作。这显然是可以理解的 https://msdn.microsoft.com/en-us/library/jj193542(v=vs.113).aspx

您可以为引用类(public virtual List<User> Users { get; set; })添加python -m spacy.en.download 键。如果你问为什么,你可以阅读What effect(s) can the virtual keyword have in Entity Framework 4.1 POCO Code First?

相关问题