我收到以下错误消息:
error CS1929: 'ConfigurationStoreOptions' does not contain a definition for 'UseSqlServer' and the best extension method overload 'SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder, string, Action<SqlServerDbContextOptionsBuilder>)' requires a receiver of type 'DbContextOptionsBuilder'
error CS1929: 'OperationalStoreOptions' does not contain a definition for 'UseSqlServer' and the best extension method overload 'SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder, string, Action<SqlServerDbContextOptionsBuilder>)' requires a receiver of type 'DbContextOptionsBuilder'
首先,问题不是因为我没有Microsoft.EntityFrameworkCore.SqlServer
,我有。
错误出现在以下代码中的AddConfigurationStore和AddOperationalStore中。它基本上不识别UseSqlServer。正如我所说,问题并不是因为我没有Microsoft.EntityFrameworkCore.SqlServer.
代码:
services.AddIdentityServer(options =>
{
options.UserInteraction.LoginUrl = "/Login";
options.UserInteraction.LogoutUrl = "/Logout";
})
.AddSigningCredential(new X509Certificate2(Configuration["Certificates:Default:Path"], Configuration["Certificates:Default:Password"]))
.AddConfigurationStore(options =>
options.UseSqlServer(Configuration["ConnectionStrings:Dayum"],
optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)))
.AddOperationalStore(options =>
options.UseSqlServer(Configuration["ConnectionStrings:Dayum"],
optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)))
.AddAspNetIdentity<ApplicationUser>();
以下操作很好:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["ConnectionStrings:Dayum"],
optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)));
我的NuGet包:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityServer4" Version="3.1.3" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="3.1.3" />
<PackageReference Include="IdentityServer4.EntityFramework" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.2" />
</ItemGroup>
<ItemGroup>
<Folder Include="Certs" />
</ItemGroup>
</Project>
我自己在一个脚手架项目中找到了答案。显然,UseSqlServer现在处于ConfigureDbContext之下。
dotnet new is4ef
services.AddIdentityServer()
.AddSigningCredential(new X509Certificate2(Configuration["Certificates:Default:Path"], Configuration["Certificates:Default:Password"]))
.AddAspNetIdentity<ApplicationUser>()
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = builder => builder.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName));
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder => builder.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName));
});