我不确定这是否应该可行,但我找不到很多关于此的信息。 我正在运行命令
迁移添加测试
尝试为我的代码第一个模型启用迁移。我得到的例外是:
System.TypeLoadException:类型'Microsoft.Data.Entity.SqlServer中的方法'Next' .SequentialGuidValueGenerator'来自程序集'EntityFramework.SqlServer,版本 = 7.0.0.0,Culture = neutral,PublicKeyToken = null'没有实现。
这意味着这还没有实现,但我发现很难相信。也许我做错了什么?
我使用的项目是使用VS2014 CTP3创建的,并设置为使用核心CLR。这是project.json:
{
"webroot" : "wwwroot",
"exclude": "wwwroot/**/*.*",
"dependencies": {
"EntityFramework.SqlServer": "7.0.0-alpha4",
"Microsoft.AspNet.Mvc": "6.0.0-alpha4",
"Microsoft.AspNet.Identity.SqlServer": "3.0.0-alpha4",
"Microsoft.AspNet.Identity.Authentication": "3.0.0-alpha4",
"Microsoft.AspNet.Security.Cookies": "1.0.0-alpha4",
"Microsoft.AspNet.Server.IIS": "1.0.0-alpha4",
"Microsoft.AspNet.Server.WebListener": "1.0.0-alpha4",
"Microsoft.AspNet.StaticFiles": "1.0.0-alpha4",
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-alpha4",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-alpha4",
"EntityFramework.Commands": "7.0.0-*"
},
"commands": {
/* Change the port number when you are self hosting this application */
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"aspnet50" : { },
"aspnetcore50" : { }
}
}
我认为这可能是版本问题,所以我将EF引用更改为:
“EntityFramework.SqlServer”:“7.0.0 - *”
这给了我关于迁移命令的这个例外:
System.Exception:TODO:没有注册“Microsoft.Data.Entity.Migrations.ModelDiffer”类型的服务。
我认为这是一个更好的例外,但我找不到任何关于如何解决这个问题。可用的音乐商店示例不使用迁移。
更新
背景和模型:
public class MyContext : DbContext
{
public DbSet<MyModel> MyModels { get; set; }
protected override void OnConfiguring(DbContextOptions options)
{
var configuration = new Configuration();
configuration.AddJsonFile("config.json");
options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString"));
base.OnConfiguring(options);
}
}
public class MyModel
{
public int MyModelId{ get; set; }
public string Name { get; set; }
}
启动:
public class Startup
{
public void Configure(IApplicationBuilder app)
{
// Setup configuration sources
var configuration = new Configuration();
configuration.AddJsonFile("config.json");
configuration.AddEnvironmentVariables();
// Set up application services
app.UseServices(services =>
{
// Add EF services to the services container
services.AddEntityFramework().AddSqlServer();
// Add MVC services to the services container
services.AddMvc();
});
// Enable Browser Link support
app.UseBrowserLink();
// Add static files to the request pipeline
app.UseStaticFiles();
}
}
也许很重要,我在Windows 10技术预览版上运行它。
更新2
对于版本问题可能很重要,我的Nuget.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetvnext/" />
<add key="NuGet.org" value="https://nuget.org/api/v2/" />
</packageSources>
<packageSourceCredentials>
<AspNetVNext>
<add key="Username" value="aspnetreadonly" />
<add key="ClearTextPassword" value="4d8a2d9c-7b80-4162-9978-47e918c9658c" />
</AspNetVNext>
</packageSourceCredentials>
</configuration>