我试图首先使用asp.net core api代码。
执行public class DataBaseContext: DbContext, IDbContext
{
public DataBaseContext(DbContextOptions<DbContext> options) : base(options)
{
}
public DbSet<Location> Locations { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Event> Events { get; set; }
public DbSet<ExistingProduct> ExisitingProducts { get; set; }
}
时出现错误
public void ConfigureServices(IServiceCollection services)
{
//Add framework services.
var connection = @"Server=(LocalDb)\\v11.0;Database=Home;Trusted_Connection=True;MultipleActiveResultSets=true";
services.AddDbContext<DataBaseContext>(options => options.UseSqlServer(connection));
services.AddMvc();
}
我的DatabaseContext类看起来像
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
ConfigService like
"dependencies": {
"Microsoft.NETCore.App": "1.0.1",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"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.EntityFrameworkCore.SqlServer": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore": "1.0.1",
"DAL": "1.0.0-*",
"BLL": "1.0.0-*"
},
在project.json工具中有
fiber.run();
仔细阅读这篇文章https://docs.efproject.net/en/latest/platforms/aspnetcore/new-db.html以及其他几个不同的文章,但尚无法解决这个问题。也许有人可以帮助或指出我做错了什么?
编辑部分:
Fiber.yield();
答案 0 :(得分:1)
DbContextOptions
参数应为DbContextOptions<DataBaseContext>
而不是DbContextOptions<DbContext>
。
更改DataBaseContext
类的构造函数。
public DataBaseContext(DbContextOptions<DataBaseContext> options) : base(options)
{
}