由于某种原因,我的EF代码优先模型不与db同步。我得到这个错误:ef代码优先模型不与db同步
{"Invalid column name 'Type_Id1'."}
该字段实际上被称为'Type_Id',所以我不知道从哪里出现1。 我有一个名为Type_Id的表列,我也在我的类型实体模型中添加了一个Type_Id。
你们有什么想法,为什么我会得到这个错误信息,加上为什么我在名字的末尾得到1?
感谢,Laziale
UPDATE:
我的任务等级:
public class Task
{
public Task()
{
Language = 1;
Grades = new HashSet<Grade>();
Categories = new HashSet<Category>();
Subjects = new HashSet<Subject>();
Rooms = new Collection<Room>();
Tools = new Collection<Tool>();
}
[Key]
public int Id { get; set; }
public string Description { get; set; }
public virtual TaskType Type { get; set; }
public string Rules { get; set; }
[Required]
[StringLength(200), MinLength(1)]
public string Name { get; set; }
public int PreperationTime { get; set; }
public int InstructionTime { get; set; }
public int TaskTime { get; set; }
public int Type_Id { get; set; }
public string VideoLink { get; set; }
[Required]
public int Language { get; set; }
public int? MinimumParticipants { get; set; }
public int? MaximumParticipants { get; set; }
public int? Rating { get; set; }
[Required]
public string CreatedBy { get; set; }
public virtual ICollection<Grade> Grades { get; set; }
public virtual ICollection<Category> Categories { get; set; }
public virtual ICollection<Subject> Subjects { get; set; }
public virtual ICollection<Room> Rooms { get; set; }
public virtual ICollection<Tool> Tools { get; set; }
}
的DbContext类:
public ApplicationDbContext() : base("DefaultConnection", false)
{
}
public DbSet<Task> Tasks { get; set; }
public DbSet<TaskType> TaskTypes { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
会为你的模型,你添加一些代码? – Bazinga
@Bazinga - 没有真正的模型,这些类拥有db结构中的属性,并且我有dbcontext类和所有类的dbset。请让我知道你是否需要任何特定的东西。 Thx帮助 – Laziale
至少发布您的POCO类的代码,并在DbContext中发布您的模型构建器。 – DevilSuichiro