【发布时间】:2017-05-16 09:07:35
【问题描述】:
当我在 EF 核心中更改类名时,我得到空的迁移构建器。
在较旧的 EF 中,它通常会自动生成重命名表的代码。
但不能在 EF 核心中工作
public class EventComment : Comment
{
[Key]
public int CommentID { get; set; }
public int? ParentID { get; set; }
public virtual EventComment Parent { get; set; }
public int EventID { get; set; }
public virtual EventMaster EventMaster { get; set; }
}
public class Comment
{
public string CommentTitle { get; set; }
public string CommentDetails { get; set; }
public int UpVoteCount { get; set; }
public int DownVoteCount { get; set; }
public int CommentEmotion { get; set; }
public string CommentedByID { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
}
现在将 EventComment 更改为 CommentMaster。迁移为空。
我使用 fluent API 进行配置
builder.Entity<EventComment>()
.HasOne(e => e.EventMaster)
.WithMany()
.HasForeignKey(m => m.EventID);
builder.Entity<EventComment>()
.HasOne(e => e.ApplicationUser)
.WithMany()
.HasForeignKey(m => m.CommentedByID);
builder.Entity<EventComment>()
.HasOne(e => e.Parent)
.WithMany()
.HasForeignKey(x => x.ParentID);
【问题讨论】:
标签: ef-code-first migration entity-framework-core