Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架代码首先不能正常工作_C#_.net_Entity Framework_Ef Code First - Fatal编程技术网

C# 实体框架代码首先不能正常工作

C# 实体框架代码首先不能正常工作,c#,.net,entity-framework,ef-code-first,C#,.net,Entity Framework,Ef Code First,我有这个简单的模型 public class Autor { [Key] int AutorID { get; set; } [Required] [MaxLength(100)] public string Nome { get; set; } [Required] [Display(Name = "Data de nascimento")] [DisplayFormat(DataFormatString = "{0:d}",

我有这个简单的模型

public class Autor
{
    [Key]
    int AutorID { get; set; }

    [Required]
    [MaxLength(100)]
    public string Nome { get; set; }

    [Required]
    [Display(Name = "Data de nascimento")]
    [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
    public DateTime Data { get; set; }

    public virtual ICollection<Livro> Livros { get; set; }
}
用法:

public class BibliotecaContext : DbContext
{
    public DbSet<Autor> Autores { get; set; }

    public DbSet<Livro> Livros { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        modelBuilder.Entity<Autor>().HasMany(p => p.Livros).WithRequired(p => p.Autor);
    }
}
当我尝试为Livro类创建强类型控制器时,我得到以下结果:


我相信这是因为AutoId属性不是公共的。

我相信这是因为AutoId属性不是公共的。

请在聚焦消息框中按Ctrl+C,然后将错误消息作为文本粘贴到问题中。请在聚焦消息框中按Ctrl+C,然后将错误消息作为文本粘贴到问题中。
public class BibliotecaContext : DbContext
{
    public DbSet<Autor> Autores { get; set; }

    public DbSet<Livro> Livros { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        modelBuilder.Entity<Autor>().HasMany(p => p.Livros).WithRequired(p => p.Autor);
    }
}