ASP.NET Identity核心不创建表

时间:2016-10-23 19:26:00

标签: asp.net-core identity

我是ASP.NET Core的新手。我尝试在dbcontext中使用此配置在ASP.NET Core中进行开发:

 protected override void OnConfiguring(DbContextOptionsBuilder options)
    {
        options.
            UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=DBName;Integrated Security=True");


    }

这是startup.cs配置:

 public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();
            services.AddEntityFramework()
               //.AddSqlServer()
               .AddDbContext<TicketContext>();.....
          }

但是当我想创建一个如下用户时:

var result = await _userManager.CreateAsync(user, "password");

,我收到以下错误:

  

无效的对象名称'AspNetUsers'

更新

在评论的“Alex”的帮助下,我做了一些修改,现在我在我的project.json中有这些:

"dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
.....
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.EntityFrameworkCore.Design": "1.0.1",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
    "Microsoft.AspNetCore.Identity": "1.0.0",
    "DataAccessLayer": "1.0.0-*",
    "AspNet.Security.OAuth.Validation": "1.0.0-alpha2-final",
    "OpenIddict": "1.0.0-*",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  },

但是当我运行“dotnet ef数据库更新”时,我收到如下错误:

“未处理的异常:System.MissingMethodException:在程序集中找不到入口点'Microsoft.EntityFrameworkCore.Design,Version = 1.0.1.0,Culture = neutral,PublicKeyToken = adb9793829ddae60'。”

更新

看起来,当以第一种代码方式使用ef核心时,你必须先进行迁移,这样才能创建表。

0 个答案:

没有答案