找不到类型或命名空间名称 'OpenIddictDbContext<,,>'
The type or namespace name 'OpenIddictDbContext<,,>' could not be found
我有问题。我今天早上打开我的项目并收到错误:
找不到类型或命名空间名称 'OpenIddictDbContext<,,>'(是否缺少 using 指令或程序集引用?)[netcoreapp1.1]
这个错误发生在我恢复和构建我的项目时。这很奇怪,因为我的 project.json 文件中确实有 "OpenIddict": "1.0.0-*",并且我正在使用参考:使用 OpenIddict;
这个问题导致我项目到处都是问题,因为他好像不认识"using 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);
}
}
我有问题。我今天早上打开我的项目并收到错误:
找不到类型或命名空间名称 'OpenIddictDbContext<,,>'(是否缺少 using 指令或程序集引用?)[netcoreapp1.1]
这个错误发生在我恢复和构建我的项目时。这很奇怪,因为我的 project.json 文件中确实有 "OpenIddict": "1.0.0-*",并且我正在使用参考:使用 OpenIddict;
这个问题导致我项目到处都是问题,因为他好像不认识"using 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);
}
}