0

我不确定这是否应该工作,但我找不到太多关于此的信息。我正在运行命令

k ef 迁移添加测试

试图为我的代码优先模型启用迁移。我得到的例外是:

System.TypeLoadException:来自程序集“EntityFramework.SqlServer,版本=7.0.0.0,Culture=neutral,PublicKeyToken=null”的类型“Microsoft.Data.Entity.SqlServer.SequentialGuidValueGenerator”中的方法“Next”没有实现。

这意味着这还没有实现,但我觉得这很难相信。也许我做错了什么?

我使用的项目是使用 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>

4

0 回答 0