我尝试使用以下命令创建数据库迁移:
dotnet ef migrations add Initial
不幸的是,由于这个错误,我不能再进步了,这里的问题是什么? 这就是我如何配置连接字符串:
首先在appsettings.json中:
{
"Data": {
"SportStoreProducts": {
"ConnectionStrings":"Server(localdb)\MSSQLLocalDB;Database=SportsStore;Trusted _Connection=True;MultipleActiveResultSets=true"
}
}
}
然后在启动时:
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public Startup(IConfiguration configuration) => Configuration = configuration;
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(
options => options.UseSqlServer(Configuration["Data:SportStoreProducts:ConnectionString"]));
我不确定EF的版本,这是我在SportStore.csproj中添加软件包的方式:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.7" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design"
Version="2.0.3" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet"
Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
从这个文件夹中,我运行命令提示符:
C:\Users\Mohsen\Google Drive\ASP.MVC Projects\SportsStore\SportsStore
我的DbContext类被调用:
ApplicationDbContext