执行dotnet ef add migration InitialMigration
给出此错误的命令A suitable constructor for type 'Vega.Repository.VegaContext' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.
我ConfigureServices
在 Startup 类上的方法如下:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddScoped<IUnitOfWork, UnitOfWork>();
var connectionString = Configuration.GetConnectionString("VegaConnection");
services.AddDbContext<VegaContext>(options =>
options.UseSqlServer(connectionString));
}
VegaContext
类是:
public class VegaContext : DbContext
{
VegaContext(DbContextOptions<VegaContext> options):base(options)
{}
public DbSet<Make> Makes { get; set; }
}
部分csproj
文件是:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
</ItemGroup>