public class Movie
{
public int Id { get; set; }
[Required]
[StringLength(255)]
public string Name { get; set; }
public virtual IList<Genre> Genre { get; set; }
public virtual IList<Cast> cast { get; set; }
[Display(Name = "Release Date")]
public DateTime ReleaseDate { get; set; }
}
public class Genre
{
public int Id { get; set; }
[Required]
[StringLength(255)]
public String Name { get; set; }
}
这是我的两个模型。它们运行得非常好,但是主键上没有实现自动增量。
我遇到了id为空的错误,无法将其插入到数据库中,这对我来说似乎是合理的。有什么想法为什么没有自动增量,其次如何添加它们?我正在使用.NET Framework 4.6中的代码优先迁移,这是一个Winforms应用程序。