2017-10-08 181 views
1

我正在使用实体框架先学习代码。在问题出现之前,我有:更新模型后更新数据库无法正常工作

public class Book 
{ 
    [Key] 
    public int Id { get; set; } 

    [Required] 
    public string Title { get; set; } 

    [Display(Name = "Publication Name")] 
    public DateTime PublicationDate { get; set; } 

    [Required] 
    public float Edition { get; set; } // We might have a 2.5 edition. Rare but happens 

    public Author Author { get; set; } 
} 

我也有几个控制器和视图。我向数据库添加了一条记录,以测试CRUD是否有效,然后将其删除。

然后我加[Required]Author Author并试图运行迁移,并且update-database。它只是喊我说:

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "assignment1.Migrations.Addrequiredtoauthorinbookcs.resources" was correctly embedded or linked into assembly "assignment1" at compile time, or that all the satellite assemblies required are loadable and fully signed. 

任何想法我做错了什么,以及如何解决它?

+0

更改为'public virtual Author Author {get;组; }'以避免循环引用。 –

+0

什么是虚拟的? – alex3wielki

+1

在实体框架中,Virtual是一个用于激活延迟加载的关键字。 –

回答

0

可能不包含resx部分的迁移。

resx.File看看resx。文件在哪里。如果不包括它可能是一个灰色的布局或在它上面可能会有问号。 右键单击源文件并选择“包含在项目中”。 或 右键单击资源文件,在高级选项卡下的属性窗口中更改“构建操作”。更改为“嵌入式资源”。建立并再试一次 我希望这会有所帮助。我以这种方式修理了我的。

+0

我最终删除了所有的表格和迁移。工作。现在就没有移民历史了。不管怎么说,还是要谢谢你 – alex3wielki