我的模型文件夹中有两个简单的 poco 类,我想使用实体框架来创建迁移。我还有一个 dbcontext 类,这是我想用作迁移的实例。
当我尝试运行时: dnx ef migrations add IntialCommit
我收到以下错误无法从程序集“Microsoft.Framework.Configuration,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”加载类型“Microsoft.Framework.Configuration.Helper.ConfigurationHelper”。
即使我有正确的包,(Microsoft.Framework.Configuration)
知道为什么我会收到此错误吗?
AnimalsContext.cs
public class Animalscontext :DbContext
{
public DbSet<Animalscontext> animals { get; set; }
public DbSet<Dog> dog { get; set; }
}
动物.cs
public class Animals
{
public int ID { get; set; }
public string Name { get; set; }
public List<Dog> dogs { get; set; }
}
狗.cs
public class Dog
{
public int ID { get; set; }
public string breed { get; set; }
}
项目.json
"dependencies": {
"EntityFramework.Commands": "7.0.0-*",
"EntityFramework.SqlServer": "7.0.0-*",
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-*",
"Microsoft.Framework.Configuration": "1.0.0-*",
"Microsoft.Framework.Configuration.CommandLine": "1.0.0-*",
"Microsoft.Framework.Configuration.Json": "1.0.0-*",
"Microsoft.Framework.Logging": "1.0.0-*",
"Microsoft.Framework.Logging.Console": "1.0.0-*",
"Microsoft.Framework.Logging.Debug": "1.0.0-*",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-*"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands"
}
启动.cs
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<Animalscontext>(DbContextOptionsBuilder => DbContextOptionsBuilder.UseSqlServer(connectionString));
输出
Using context 'Animalscontext'.
System.TypeLoadException: Could not load type 'Microsoft.Framework.Configuration.Helper.ConfigurationHelper' from assembly 'Microsoft.Framework.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
at Microsoft.Framework.Configuration.JsonConfigurationExtensions.AddJsonFile(IConfigurationBuilder configuration, String path, Boolean optional)
at WebApplication2.Startup..ctor(IHostingEnvironment env, IApplicationEnvironment appEnv) in C:\Users\JConterio\Documents\Visual Studio 2015\Projects\WebApplication2\src\WebApplication2\Startup.cs:line 21
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Framework.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
at Microsoft.Framework.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type)
at Microsoft.AspNet.Hosting.Startup.StartupLoader.LoadMethods(Type startupType, IList`1 diagnosticMessages)
at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureStartup()
at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureApplicationServices()
at Microsoft.AspNet.Hosting.Internal.HostingEngine.get_ApplicationServices()
at Microsoft.Data.Entity.Design.DbContextOperations.TryCreateContextFromStartup(Type type)
at Microsoft.Data.Entity.Design.DbContextOperations.CreateContext(String contextType)
at Microsoft.Data.Entity.Design.MigrationsOperations.AddMigration(String name, String contextType)
at Microsoft.Data.Entity.Commands.Program.AddMigration(String name, String context)
at Microsoft.Data.Entity.Commands.Program.<>c__DisplayClass7_6.<Main>b__15()
at Microsoft.Dnx.Runtime.Common.CommandLine.CommandLineApplication.Execute(String[] args)
at Microsoft.Data.Entity.Commands.Program.Main(String[] args)
Could not load type 'Microsoft.Framework.Configuration.Helper.ConfigurationHelper' from assembly 'Microsoft.Framework.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.