error loading database initializer with EF6(使用 EF6 加载数据库初始化程序时出错)
问题描述
我一直在尝试遵循本教程... http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application 但我不断收到以下错误...
I have been trying to follow this tutorial ... http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application but I keep getting the following error ...
system.invalidoperationexception = {"设置数据库失败'WeddingPreparations.Dal.WeddingInitializer 类型的初始化程序,KevinLisaWedding' 用于 DbContext 类型'WeddingPreparations.Dal.WeddingContext' 在应用程序中指定配置.有关详细信息,请参阅内部异常."}
system.invalidoperationexception = {"Failed to set database initializer of type 'WeddingPreparations.Dal.WeddingInitializer, KevinLisaWedding' for DbContext type 'WeddingPreparations.Dal.WeddingContext' specified in the application configuration. See inner exception for details."}
内部异常是...
{"无法从程序集 'EntityFramework,版本 = 6.0.0.0,文化 = 中性,PublicKeyToken=b77a5c561934e089'.":"WeddingPreparations.Dal.WeddingContext"}
{"Could not load type 'WeddingPreparations.Dal.WeddingContext' from assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.":"WeddingPreparations.Dal.WeddingContext"}
堆栈跟踪是...
我还搜索了高低,为什么我没有任何运气就收到此错误,我已经下载了完成的项目并将其与我的项目进行了比较,但没有任何运气.
I've also searched high and low for why I am getting this error without any luck and I've downloaded the completed project and compared it to mine without any luck.
我当前的代码如下.
在WeddingPreparations项目中……
In the WeddingPreparations project ...
和
我在这个项目中的模型如下
My model in this project is as follows
在 mvc 项目中,我有以下 web.config 文件...
In the mvc project I have the following web.config file ...
在我的家庭控制器中,我正在执行以下代码......
And in my home controller I'm executing the following code ...
如果我没记错的话,它应该创建数据库并使用初始化程序中指定的数据为其播种......但是我得到的只是那个错误,我似乎无法弄清楚......任何方向表示赞赏.
which is supposed to create the database if I'm not mistaking and seed it with the data specified in the initializer ... however all I get is that error and I can't seem to figure it out ... any direction is appreciated.
我尝试像在教程中那样重新创建项目,但我仍然遇到同样的错误.肯定有一些代码丢失了......要么我错过了......要么教程没有它.
I tried recreating the project as one just like they did in the tutorial and but i still end up with the same error. There's gotta be some code missing ... either I missed it ... or the tutorial just doesn't have it.
推荐答案
在你的 web.config
文件中你有这个:
In your web.config
file you have this:
这表示在名为 KevinLisaWedding
的程序集中查找名为 WeddingPreparations.Dal.WeddingInitializer
的类.由于您的程序集称为 WeddingPreparations
您需要将配置更改为:
This says look for a class called WeddingPreparations.Dal.WeddingInitializer
in the assembly called KevinLisaWedding
. As your assembly is called WeddingPreparations
you need to change the config to this:
这篇关于使用 EF6 加载数据库初始化程序时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!