由於某種原因,我的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