41-EF Core数据升级

假设我们现在增加了一个实体

public class Article
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }
    public virtual UserInfo User { get; set; }
}Code language: JavaScript (javascript)

DBcONTEXT上下文中增加dbset

public class MyDBContent: DbContext
{
    public MyDBContent(DbContextOptions<MyDBContent> options) : base(options)
    {
    }

    public DbSet<UserInfo> Users { get; set; }
    public DbSet<Article> Articles { get; set; }
}Code language: HTML, XML (xml)

用户表页要改 增加一个List

public virtual List<Article> Articles { set; get; }Code language: JavaScript (javascript)

我们执行 命令 Add-Migration migrationName 和 Update-Database 成功后刷新数据库可以看到表和字段都相应的加上了 ,当然还有外键

PM> Update-Database
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using 'C:\Users\M\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 2.0.3-rtm-10026 initialized 'MyDBContent' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (16ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT OBJECT_ID(N'__EFMigrationsHistory');
Microsoft.EntityFrameworkCore.Database.Command[20101]Code language: JavaScript (javascript)

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注