小编Tec*_*her的帖子

使用实体框架,代码优先,无自动增量

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 …

c# entity-framework code-first winforms

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

code-first ×1

entity-framework ×1

winforms ×1