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; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的 2 个模型。它们工作得很好,除了主键上没有实现自动增量之外。
我收到 id 为空的错误,并且无法插入数据库,这对我来说似乎是逻辑的。任何想法为什么没有任何自动增量,其次我如何添加它们?我在 .NET Framework 4.6 中使用代码优先迁移,它是一个 Winforms …