【发布时间】:2016-04-04 07:10:21
【问题描述】:
实体类型“Notepad.Models.Note”上的导航“标签”尚未添加到模型中,或被忽略,或 entityType 被忽略。
public class Note
{
public Note()
{
CreationDate = DateTime.Now;
Tags = new HashSet<Tag>();
Parts = new HashSet<Part>();
}
public int ID { get; set; }
public virtual ICollection<Tag> Tags { get; set; }
public virtual ICollection<Part> Parts { get; set; }
public DateTime? CreationDate { get; set; }
}
public class Tag
{
public Tag()
{
Notes = new HashSet<Note>();
}
public int ID { get; set; }
public string Name { get; set; }
public virtual ICollection<Note> Notes { get; set; }
}
添加迁移时会发生这种情况:
dnx ef 迁移添加 DbData -c DataDbContext
你认为为什么会这样?
编辑: 数据数据库上下文:
public class DataDbContext : DbContext
{
public DbSet<Note> Notes { get; set; }
public DbSet<Tag> Tags { get; set; }
public DbSet<Part> Parts { get; set; }
}
【问题讨论】:
-
显示
Tag的代码 -
您是否将 DbSet
添加到 DataDbContext 中? -
@MarcinZablocki 我已经把它粘贴到问题上,你可以看看是否一切正确
标签: c# entity-framework asp.net-core dnx entity-framework-core