Code-First数据迁移 

首先要通过NuGet将EF升级至最新版本。

新建MVC 4项目MvcMigrationDemo

添加数据模型 Person 和 Department,定义如下:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.ComponentModel.DataAnnotations;
 6 using System.ComponentModel.DataAnnotations.Schema;
 7 
 8 namespace MvcMigrationDemo.Models
 9 {
10     public class Person
11     {
12         [Key]
13         public int PersonID { get; set; }
14 
15         [Required]
16         [MaxLength(20)]
17         public string PersonName { get; set; }
18 
19         public virtual Department Departmant { get; set; }
20 
21     }
22 }
Person

相关文章:

  • 2021-08-18
猜你喜欢
  • 2022-01-07
  • 2021-07-02
  • 2021-12-24
相关资源
相似解决方案