简体   繁体   English

生成的ToList将不起作用

[英]Generated ToList won't work

I'm very new to C# and I'm trying to make a basic little project. 我是C#的新手,正在尝试做一个基本的小项目。 When I try to go to the generated index page (On the view -> Add -> View and then I just gave it the name Index and template List) 当我尝试转到生成的索引页面时(在视图上->添加->视图,然后我给它命名为索引和模板列表)

When I try to use this link to the index page; 当我尝试使用此链接指向索引页面时;

<ul><li>@Html.ActionLink("Beheer", "Index", "Competenties")</li></ul>

I keep getting this error. 我不断收到此错误。

An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code EntityFramework.dll中发生类型'System.InvalidOperationException'的异常,但未在用户代码中处理

Additional information: The model backing the 'DatabankCompetenties' context has changed since the database was created. 附加信息:自创建数据库以来,支持“ DatabankCompetenties”上下文的模型已更改。 Consider using Code First Migrations to update the database ( http://go.microsoft.com/fwlink/?LinkId=238269 ). 考虑使用Code First Migrations更新数据库( http://go.microsoft.com/fwlink/?LinkId=238269 )。

I tried resetting the Database, rerolling all the tables and using the command update-database, but nothing seems to work. 我尝试重置数据库,重新滚动所有表并使用命令update-database,但似乎没有任何效果。

You modify your Database schema, but you don't migrate the changes. 您修改数据库模式,但不迁移所做的更改。 https://msdn.microsoft.com/en-us/data/jj591621.aspx https://msdn.microsoft.com/zh-CN/data/jj591621.aspx

  1. Open the Package Manager Console in Visual Studio 在Visual Studio中打开程序包管理器控制台
  2. Select the project where is the database classes 选择项目所在的数据库类
  3. Enable-Migrations command Enable-Migrations命令
  4. Add-Migration [Name] command Add-Migration [名称]命令
  5. Update-Database command 更新数据库命令

Since you are very new to C# I'll give you a very basic solution, which helped me out quite a few times. 由于您是C#的新手,因此我将为您提供一个非常基本的解决方案,该解决方案帮助了我很多次。

  1. Add-Migration (check which migration needs updating) 添加迁移(检查哪些迁移需要更新)
  2. delete the recently added migration and the old one 删除最近添加的迁移和旧迁移
  3. Add-Migration (Now you know which migration needs to be updated, so you can give it the proper name) Add-Migration(现在您知道需要更新哪个迁移,因此可以为其指定适当的名称)
  4. Delete all the tables in your DB (including _MigrationHistory) 删除数据库中的所有表(包括_MigrationHistory)
  5. Update-Database -verbose 更新数据库-详细

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM