[英]The type or namespace name 'OpenIddictDbContext<,,>' could not be found
我有個問題。 我今天早上打開了我的項目並得到了錯誤:
找不到類型或命名空間名稱'OpenIddictDbContext <,,>'(您是否缺少using指令或程序集引用?)[netcoreapp1.1]
我恢復並構建項目時發生此錯誤。 這很奇怪,因為我在我的project.json文件中有“OpenIddict”:“1.0.0- *” ,我正在使用引用: using OpenIddict ;
這個問題在我的項目中到處都會出現問題,因為他似乎沒有認識到“使用OpenIddict”
如果它有幫助,這是我得到錯誤的例子(ApplicationDbContext.cs)
namespace Overnight.Db
{
//the error: The type or namespace name 'OpenIddictDbContext<,,>' could not be found (are you missing a using directive or an assembly reference?)
public class ApplicationDbContext : OpenIddictDbContext<ApplicationUser, ApplicationRole, Guid>
{
要么
//the error: 'OpenIddictDbContext<ApplicationUser, ApplicationRole, Guid>' does not contain a constructor that takes 1 arguments
protected override void OnModelCreating(ModelBuilder builder)
{
這是我的project.json:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
},
"Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final",
"AspNet.Security.Oauth.Validation": "1.0.0-alpha2-final",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"OpenIddict": "1.0.0-*",
"Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.1-*",
"Npgsql.EntityFrameworkCore.PostgreSQL.Design": "1.0.1-*",
"Bogus": "7.1.6",
"Overnight.Models": {
"target": "project",
"version": "1.0.0-*"
}
},
"frameworks": {
"netcoreapp1.1": {}
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final"
}
}
}
這很奇怪,因為我在可視代碼中打開的每個項目都有這個錯誤,所以我不認為它與我的項目有關。
從beta2開始,OpenIddict不再帶有可以子類化的專用DbContext
,因為這種模式 - 從ASP.NET Core Identity繼承 - 被證明是相當不切實際的。
相反,現在鼓勵您直接從IdentityDbContext
繼承並通過從ConfigureServices
調用options.UseOpenIddict()
來注冊OpenIddict所需的實體集:
project.json:
"dependencies": {
"OpenIddict": "1.0.0-*",
"OpenIddict.EntityFrameworkCore": "1.0.0-*",
"OpenIddict.Mvc": "1.0.0-*"
}
啟動:
services.AddDbContext<ApplicationDbContext>(options =>
{
// Configure the context to use Microsoft SQL Server.
options.UseSqlServer(configuration["Data:DefaultConnection:ConnectionString"]);
// Register the entity sets needed by OpenIddict.
// Note: use the generic overload if you need
// to replace the default OpenIddict entities.
options.UseOpenIddict();
});
// Register the OpenIddict services.
services.AddOpenIddict(options =>
{
// Register the Entity Framework stores.
options.AddEntityFrameworkCoreStores<ApplicationDbContext>();
});
ApplicationDbContext:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions options)
: base(options) { }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.