当前位置: 首页 > 编程语言 > C#

找不到类型或命名空间名称“OpenIddictDbContext”Share

时间:2023-04-10 14:10:54 C#

Thetypeornamespacename'OpenIddictDbContext'couldnotbefound我今天早上打开我的项目并收到错误:找不到类型或命名空间名称“OpenIddictDbContext”(是否缺少using指令或程序集引用?)[netcoreapp1.1]当我恢复和构建项目。这很奇怪,因为我的project.json文件中有"OpenIddict":"1.0.0-*"并且我正在使用引用:使用OpenIddict;这个问题在我的项目中无处不在,因为他似乎没有识别“使用OpenIddict”如果它有帮助,这是我得到错误的例子(ApplicationDbContext.cs)namespaceOvernight.Db{//theerror:Thetypeor找不到命名空间名称“OpenIddictDbContext”(是否缺少using指令或程序集引用?)(ModelBuilderbuilder){这是我的儿子:project.j"version":"1.0.0-*","buildOptions":{"emitEntryPoint":true},"dependencies":{"Microsoft.NETCore.App":{“类型”:“平台”,“版本”:“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.EntityFrameworkCorere.PostgreSQL":"1.0.1-*","Npgsql.EntityFrameworkCore.PostgreSQL.Design":"1.0.1-*","Bogus":"7.1.6","Overnight.Models":{"target“:“项目”,“版本”:“1.0.0-*”}},“框架”:{“netcoreapp1.1”:{}},“工具”:{“Microsoft.EntityFrameworkCore.Tools”:{“version":"1.0.0-preview2-final"}}}这很奇怪,因为我在可视化代码中打开的每个项目都有这个错误,所以我认为它与我的项目无关,因为beta2,OpenIddict不再带有一个可以子类化的专用DbContext,因为这种模式-从ASP.NETCoreIdentity继承-已被证明是相当不切实际的。相反,现在鼓励您直接从IdentityDbContext继承并通过从ConfigureServices调用options.UseOpenIddict()来注册OpenIddict所需的实体集:project.json:"dependencies":{"OpenIddict":"1.0.0-*","OpenIddict.EntityFrameworkCore":"1.0.0-*","OpenIddict.Mvc":"1.0.0-*"}Startup:services.AddDbContext(options=>{//配置上下文以使用MicrosoftSQLServer.options.UseSqlServer(configuration["Data:DefaultConnection:ConnectionString"]);//注册OpenIddict所需的实体集。//注意:如果需要,请使用通用重载//替换默认的OpenIddict实体。选项。UseOpenIddict();});//注册OpenIddictservices.services.AddOpenIddict(options=>{//注册实体框架stores.options.AddEntityFrameworkCoreStores();});ApplicationDbContext:以上是C#学习教程:找不到类型或命名空间名称如果《OpenIddictDbContext》分享的所有内容对您都有用,需要进一步了解C#学习教程希望大家多多关注它—publicclassApplicationDbContext:IdentityDbContext{publicApplicationDbContext(DbContexttOptionsoptions):base(options){}protectedoverridevoidOnModelCreating(ModelBuilderbuilder){base.OnModelCreating(builder);}//自定义ASP.NETIdentity模型并在需要时覆盖默认值。//例如,您可以重命名ASP.NETIdentity表名称等。//在调用base.OnModelCreating(builder)之后添加自定义项;明源: