在 Entity Framework Code First 方法中启用迁移?

Enable Migration in Entity Framework Code First approach?

我只是想在 entity framework 代码优先方法中启用迁移。我正在研究 AirlineManagementSystem。

我创建了一个 class 平面。

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; }
    }
}

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

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; }
    }

}

所以一架飞机可以有很多用户。

请告诉我如何在包管理控制台中启用迁移?

您可以按照以下说明进行操作。这很清楚 https://msdn.microsoft.com/en-us/library/jj193542(v=vs.113).aspx

您可以添加一个virtual键作为参考class(public virtual List<User> Users { get; set; })。如果你问为什么,你可以阅读这篇What effect(s) can the virtual keyword have in Entity Framework 4.1 POCO Code First?