使用EF6加载数据库初始化程序时出错 [英] error loading database initializer with EF6

查看:240
本文介绍了使用EF6加载数据库初始化程序时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图关注本教程... http://www.asp.net/mvc/tutorials/getting-started-with-ef-using- mvc / creation-an-entity-framework-data-model-for-a-asp-net-mvc-application ,但是我不断收到以下错误...


system.invalidoperationexception = {无法为DbContext类型
'WeddingPreparations设置数据库
类型为'WeddingPreparations.Dal.WeddingInitializer
KevinLisaWedding' $ d

$ p

内部异常是...


{无法从
装入EntityFramework,Version = 6.0加载类型'WeddingPreparations.Dal.WeddingContext' .0.0,文化e = neutral,
PublicKeyToken = b77a5c561934e089'。:WeddingPreparations.Dal.WeddingContext}


堆栈跟踪是...

 在System.Data.Entity.Internal.InitializerConfig.TryGetInitializer(Type requiredContextType,String contextTypeName,String initializerTypeName,Boolean isDisabled,Func`1 initializerArgs,Func`3 exceptionMessage)
在System.Data.Entity.Internal.InitializerConfig。<> c__DisplayClass6。< TryGetInitializerFromEntityFrameworkSection> b__1(ContextElement e)
在System.Linq .Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
在System.Linq.Enumerable.FirstOrDefault [TSource](IEnumerable`1源,Func`2谓词)
在System.Data.Entity.Internal.InitializerConfig System.Data.Entity.Internal.InitializerConfig.TryGetInitializer(类型contextType)中的$ T $ B $ System.Data.Entity.Infrastructure.Dependency中的
Resolution.AppConfigDependencyResolver.GetServiceFactory(Type type,String name)
在System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver。c__DisplayClass1。< GetService> b__0(Tuple`2 t)
在System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key,Func`2 valueFactory)
在System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetService(Type type,Object key)
在System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain。c__DisplayClass3。< GetService> b__0(IDbDependencyResolver r)
在System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
在System.Linq.Enumerable.FirstOrDefault [TSource](IEnumerable`1源,Func`2谓词)
在System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(类型类型,对象键)
在System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2.GetService(类型,对象键)
在System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService(IDbDependencyResolver解析器,类型类型)
在System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
在System.Data.Entity.Internal.LazyInternalContext。< InitializeDatabase> b__4(InternalContext c)
在System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput输入)
在System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
在System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
在System.Data.Entity.Internal.InternalContext。 Initialize()
在System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
在System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
在System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
在System.Data.Entity.Infrastructure.DbQuery `1.System.Collections.Generic.IEnumerable< TResult> .GetEnumerator()
在System.Collections.Generic.List`1..ctor(IEnumerable`1集合)
在System.Linq.Enumerable C:\Users\kdonde\Documents\Visual Studio 2013中的KevinLisaWedding.Controlers.HomeController.Index()中的.ToList [TSource](IEnumerable`1源)
\Projects\KevinLisaWedding\ KevinLisaWedding\Controllers\HomeController.cs:第14行
在lambda_method(Closure,ControllerBase,Object [])
在System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,Object []参数)
在System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary`2参数)
在System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary`2参数)
在System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.Invok eSyncActionMethod()
在System.Web.Mvc.Async.AsyncControllerActionInvoker。< BeginInvokeSynchronousActionMethod> b__36(IAsyncResult asyncResult,ActionInvocation innerInvokeState)
在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate (IAsyncResult asyncResult)
在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
在System.Web.Mvc.Async.AsyncResultWrapper.End [TResult](IAsyncResult asyncResult,Object标签)
在System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters。< InvokeActionMethodFilterAsynchronouslyRecursive> b__3c()
在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters。  c__DisplayClass45。< InvokeActionMethodFilterAsynchronouslyRecursive> b__3e()

我也搜索了高低为什么我得到这个错误没有任何运气,我已经下载完成的项目,并将其与我没有任何运气。



我目前的代码如下。



在WeddingPreparations项目中...

 命名空间WeddingPreparations.Dal 
{
public class WeddingContext:DbContext
{
public WeddingContext()
:base(WeddingContext)
{

}

//这个类的任何实体引用将被隐式包含。
public DbSet< Invitee>邀请者{get;组;

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove< PluralizingTableNameConvention>();
//base.OnModelCreating(modelBuilder);
}
}
}

  namespace WeddingPreparations.Dal 
{
public class WeddingInitializer:System.Data.Entity.DropCreateDatabaseIfModelChanges< WeddingContext>
{
protected override void Seed(WeddingContext context)
{
//base.Seed(context);
var invitees = new List< Invitee>
{
new Invitee {FirstName =FName1,LastName =LName1,Attending = true,HotelRoomRequired = true,Notes =我是新郎:)},
新Invitee {FirstName =FName2,LastName =LName2,Attending = true,HotelRoomRequired = true,Notes =我是新娘!}

};
invitees.ForEach(i => context.Invitees.Add(i));
context.SaveChanges();
}
}
}

我的这个项目的模型是如下

 命名空间WeddingPreparations.Models 
{
public class Invitee
{
public int Id {get;组; }
public string FirstName {get;组; }
public string LastName {get;组; }
public bool参加{get;组; }
public bool HotelRoomRequired {get;组; }
public string Notes {get;组; }
}
}

在mvc项目中,我有以下网页。配置文件...

 <?xml version =1.0encoding =utf-8?>有关如何配置ASP.NET应用程序的更多信息,请访问
http://go.microsoft.com/fwlink/?LinkId=301880
- >
< configuration>
< configSections>

< section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =假/>
<! - 有关实体框架配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >< / configSections>
< connectionStrings>
< add name =WeddingContextconnectionString =Data Source =(LocalDb)\v11.0; Initial Catalog = WeddingInvites; Integrated Security = SSPI; providerName =System.Data.SqlClient/>
< / connectionStrings>
< appSettings>
< add key =webpages:Versionvalue =3.0.0.0/>
< add key =webpages:Enabledvalue =false/>
< add key =ClientValidationEnabledvalue =true/>
< add key =UnobtrusiveJavaScriptEnabledvalue =true/>
< / appSettings>
< system.web>
< compilation debug =truetargetFramework =4.5/>
< httpRuntime targetFramework =4.5/>
< /system.web>
<运行时>
< assemblyBinding xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentAssembly>
< assemblyIdentity name =System.Web.HelperspublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.MvcpublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-5.0.0.0newVersion =5.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.OptimizationpublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-1.1.0.0newVersion =1.1.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.WebPagespublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =WebGreasepublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =0.0.0.0-1.5.2.14234newVersion =1.5.2.14234/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =Newtonsoft.JsonpublicKeyToken =30ad4fe6b2a6aeedculture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-6.0.0.0newVersion =6.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =NinjectpublicKeyToken =c7192dc5380945e7culture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-3.2.0.0newVersion =3.2.0.0/>
< / dependentAssembly>
< / assemblyBinding>
< / runtime>
< system.webServer>
<处理程序>
< remove name =ExtensionlessUrlHandler-Integrated-4.0/>
< remove name =OPTIONSVerbHandler/>
< remove name =TRACEVerbHandler/>
< add name =ExtensionlessUrlHandler-Integrated-4.0path =*。 verb =*type =System.Web.Handlers.TransferRequestHandlerpreCondition =integratedMode,runtimeVersionv4.0/>
< / handlers>
< /system.webServer>
< entityFramework>
< contexts>
< context type =WeddingPreparations.Dal.WeddingContext>
< databaseInitializer type =WeddingPreparations.Dal.WeddingInitializer,KevinLisaWedding/>
< / context>
< / contexts>
< defaultConnectionFactory type =System.Data.Entity.Infrastructure.LocalDbConnectionFactory,EntityFramework>
< parameters>
< parameter value =v11.0/>
< / parameters>
< / defaultConnectionFactory>
< providers>
< provider invariantName =System.Data.SqlClienttype =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
< / providers>
< / entityFramework>
< / configuration>

在我的家庭控制器中,我正在执行以下代码...

  WeddingPreparations.Dal.WeddingContext ctx = new WeddingPreparations.Dal.WeddingContext(); 
var x = ctx.Invitees.ToList();

如果我不会错误地创建数据库,并用指定的数据种子初始化程序...但是我得到的是这个错误,我似乎无法弄清楚...任何方向都是赞赏。



更新



我尝试像在教程中一样重新创建项目,但我仍然会遇到相同的错误。有一些代码丢失...或者我错过了...或者教程没有了。

解决方案

在您的 web.config p>

 < contexts> 
< context type =WeddingPreparations.Dal.WeddingContext>
< databaseInitializer type =WeddingPreparations.Dal.WeddingInitializer,KevinLisaWedding/>
< / context>
< / contexts>

这表示寻找一个名为 WeddingPreparations.Dal.WeddingInitializer 在汇编中调用 KevinLisaWedding 。您的装配被称为 WeddingPreparations ,您需要将配置更改为:

 <上下文> 
< context type =WeddingPreparations.Dal.WeddingContext,WeddingPreparations>
< databaseInitializer type =WeddingPreparations.Dal.WeddingInitializer,WeddingPreparations/>
< / context>
< / contexts>


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 = {"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."}

The inner exception is ...

{"Could not load type 'WeddingPreparations.Dal.WeddingContext' from assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.":"WeddingPreparations.Dal.WeddingContext"}

The stack trace is ...

   at System.Data.Entity.Internal.InitializerConfig.TryGetInitializer(Type requiredContextType, String contextTypeName, String initializerTypeName, Boolean isDisabled, Func`1 initializerArgs, Func`3 exceptionMessage)
   at System.Data.Entity.Internal.InitializerConfig.<>c__DisplayClass6.<TryGetInitializerFromEntityFrameworkSection>b__1(ContextElement e)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at System.Data.Entity.Internal.InitializerConfig.TryGetInitializerFromEntityFrameworkSection(Type contextType)
   at System.Data.Entity.Internal.InitializerConfig.TryGetInitializer(Type contextType)
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetServiceFactory(Type type, String name)
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple`2 t)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService(IDbDependencyResolver resolver, Type type)
   at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
   at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
   at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
   at System.Data.Entity.Internal.InternalContext.Initialize()
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at KevinLisaWedding.Controllers.HomeController.Index() in c:\Users\kdonde\Documents\Visual Studio 2013\Projects\KevinLisaWedding\KevinLisaWedding\Controllers\HomeController.cs:line 14
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__36(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass45.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3e()

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.

My current code is as follows.

In the WeddingPreparations project ...

namespace WeddingPreparations.Dal
{
    public class WeddingContext : DbContext
    {
        public WeddingContext()
            : base("WeddingContext")  
        {

        }

        // Any entities reference by this class will be implicitly included.
        public DbSet<Invitee> Invitees { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            //base.OnModelCreating(modelBuilder);
        }
    }
}

and

namespace WeddingPreparations.Dal
{
    public class WeddingInitializer : System.Data.Entity.DropCreateDatabaseIfModelChanges<WeddingContext>
    {
        protected override void Seed(WeddingContext context)
        {
            //base.Seed(context);
            var invitees = new List<Invitee>
            {
                new Invitee{ FirstName= "FName1", LastName= "LName1", Attending = true, HotelRoomRequired= true, Notes="I'm the groom! :)"},
                new Invitee{ FirstName= "FName2", LastName= "LName2", Attending = true, HotelRoomRequired= true, Notes="I'm the bride! :)"}

            };
            invitees.ForEach(i => context.Invitees.Add(i));
            context.SaveChanges();
        }
    }
}

My model in this project is as follows

namespace WeddingPreparations.Models
{
    public class Invitee
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public bool Attending { get; set; }
        public bool HotelRoomRequired { get; set; }
        public string Notes { get; set; }
     }
}

In the mvc project I have the following web.config file ...

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <configSections>

    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <connectionStrings>
    <add name="WeddingContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=WeddingInvites;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <entityFramework>
    <contexts>
      <context type="WeddingPreparations.Dal.WeddingContext">
        <databaseInitializer type="WeddingPreparations.Dal.WeddingInitializer, KevinLisaWedding" />
      </context>
    </contexts>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" >
    <parameters>
      <parameter value="v11.0"/>
    </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

And in my home controller I'm executing the following code ...

WeddingPreparations.Dal.WeddingContext ctx = new WeddingPreparations.Dal.WeddingContext();
var x = ctx.Invitees.ToList();

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.

Update

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.

解决方案

In your web.config file you have this:

<contexts>
    <context type="WeddingPreparations.Dal.WeddingContext">
        <databaseInitializer type="WeddingPreparations.Dal.WeddingInitializer, KevinLisaWedding" />
    </context>
</contexts>

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:

<contexts>
    <context type="WeddingPreparations.Dal.WeddingContext, WeddingPreparations">
        <databaseInitializer type="WeddingPreparations.Dal.WeddingInitializer, WeddingPreparations" />
    </context>
</contexts>

这篇关于使用EF6加载数据库初始化程序时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆