算术运算导致溢出(更新asp核心数据库)

时间:2016-09-10 15:37:42

标签: asp.net-core-mvc asp.net-core-webapi

我刚刚转到asp核心。我想在asp核心中使用ef创建一个数据库。我添加了一个名为Person的smaple类并在DbContext中使用它,然后在我的项目的根目录中的命令行中添加了dotnet ef,之后添加了一个迁移到项目但是当我尝试在命令行中更新数据库时,我遇到了这个错误:

  

算术运算导致溢出

这是我的代码: 这是我的项目json:

   {
   "buildOptions": {
   "emitEntryPoint": true,
   "preserveCompilationContext": true
   },
   "dependencies": {
   "EntityFramework.Core": "7.0.0-rc1-final",
   "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
   "Microsoft.AspNetCore.Mvc": "1.0.0",
   "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
   "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
   "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
   "Microsoft.EntityFrameworkCore.SqlServer.Design": {
     "version": "1.0.0",
     "type": "build"
   },
   "Microsoft.EntityFrameworkCore.Tools": {
     "version": "1.0.0-preview2-final",
     "type": "build"
   },
  "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
  "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
  "Microsoft.Extensions.Configuration.Json": "1.0.0",
  "Microsoft.Extensions.Logging": "1.0.0",
  "Microsoft.Extensions.Logging.Console": "1.0.0",
  "Microsoft.Extensions.Logging.Debug": "1.0.0",
  "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
  "Microsoft.NETCore.App": {
    "version": "1.0.0",
    "type": "platform"
  }
},
"Microsoft.EntityFrameworkCore.Tools": {
    "version": "1.0.0-preview2-final",
    "imports": [
      "portable-net45+win8"
    ]
},
"frameworks": {
    "netcoreapp1.0": {
    "imports": [
      "dotnet5.6",
      "portable-net45+win8"

    ]
  }
},
"publishOptions": {
  "include": [
    "wwwroot",
    "Views",
    "Areas/**/Views",
    "appsettings.json",
    "web.config"
  ]
},
"runtimeOptions": {
    "configProperties": {
    "System.GC.Server": true
  }
},
"scripts": {
  "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath%     --framework %publish:FullTargetFramework%" ]
},
"tools": {
  "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-  final",
  "Microsoft.EntityFrameworkCore.Tools": {
    "version": "1.0.0-preview1-final",
    "imports": [
      "portable-net45+win8+dnxcore50",
      "portable-net45+win8"
    ]
  }
}

}

appsetting.json:

"ConnectionStrings": {
  "ApplicationDbContextConnection": "Data Source=(local);Initial Catalog=TestDbCore2016;Integrated Security = true"
}

}

的DbContext:

  public class ApplicationDbContext : DbContext
  {
      private readonly IConfigurationRoot _configuration;
      public ApplicationDbContext(IConfigurationRoot configuration)
      {
          _configuration = configuration;
      }

      public DbSet<Person> Persons { get; set; }
      protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
      {
             optionsBuilder.UseSqlServer(_configuration["ConnectionStrings:ApplicationDbContextConnection"]);
      }
  }

启动类

public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddEnvironmentVariables();
        Configuration = builder.Build();
    }

    public IConfigurationRoot Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddMvc();
        services.AddSingleton<IConfigurationRoot>(provider => { return Configuration; });
        services.AddDbContext<ApplicationDbContext>(ServiceLifetime.Scoped);
        services.AddScoped<IUnitOfWork, ApplicationDbContext>();
        services.AddScoped<IPersonService, PersonService>();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();

        app.UseMvc();
        if (env.IsDevelopment())
        {
            app.UseDatabaseErrorPage();
        }
    }
}

0 个答案:

没有答案