c# - 值不能为空,参数名称:seqOwner
问题描述
对于一个项目,我正在尝试使用身份作为身份验证服务。为此,我试图将实体映射到现有数据库。我认为这部分已经完成并且现在可以工作了,但是当我尝试登录时,会抛出一个错误,我不知道如何修复它。
就是说 seqOwner 不能为空,我不明白 Oracle 为什么要创建序列。
这是我的 IdentityModel.cs
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.HasDefaultSchema("SCHEMA1");
modelBuilder.Entity<ApplicationUser>().ToTable("SCHEMA1.PERSONNELS", "SCHEMA1$USER");
modelBuilder.Entity<ApplicationUser>().Property(p => p.UserName).HasColumnName("PE_USERNAME");
modelBuilder.Entity<ApplicationUser>().Property(p => p.PasswordHash).HasColumnName("PE_MDPEXTRA").IsOptional();
modelBuilder.Entity<ApplicationUser>().Property(p => p.Email).HasColumnName("PE_MAIL");
modelBuilder.Entity<ApplicationUser>().Property(p => p.Id).HasColumnName("PE_ID");
modelBuilder.Entity<ApplicationUser>().Ignore(c => c.AccessFailedCount)
.Ignore(c => c.LockoutEnabled)
.Ignore(c => c.LockoutEndDateUtc)
.Ignore(c => c.EmailConfirmed)
.Ignore(c => c.SecurityStamp)
.Ignore(c => c.TwoFactorEnabled)
.Ignore(c => c.PhoneNumberConfirmed)
.Ignore(c => c.PhoneNumber);
}
这是连接字符串,工作正常我可以看到表格和序列
<add name="IdentityContext" connectionString="DATA SOURCE=gesmardev.world;PASSWORD=gesmar;PERSIST SECURITY INFO=True;USER ID="GESMAR$USER"" providerName="Oracle.ManagedDataAccess.Client" />
这是错误堆栈:
Oracle.ManagedDataAccess.EntityFramework.EntityUtils.CheckArgumentNull(T value, String parameterName) +44
Oracle.ManagedDataAccess.EntityFramework.OracleMigrationSqlGenerator.GenerateSequenceCreate(String seqOwner, String seqName) +47
Oracle.ManagedDataAccess.EntityFramework.OracleMigrationSqlGenerator.Generate(CreateTableOperation createTableOperation) +1278
CallSite.Target(Closure , CallSite , OracleMigrationSqlGenerator , Object ) +193
Oracle.ManagedDataAccess.EntityFramework.OracleMigrationSqlGenerator.<GenerateStatements>b__2(Object op) +183
Oracle.ManagedDataAccess.EntityFramework.EntityUtils.Each(IEnumerable`1 ts, Action`1 action) +130
Oracle.ManagedDataAccess.EntityFramework.OracleMigrationSqlGenerator.GenerateStatements(IEnumerable`1 migrationOperations) +81
Oracle.ManagedDataAccess.EntityFramework.OracleMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken) +94
System.Data.Entity.Migrations.DbMigrator.GenerateStatements(IList`1 operations, String migrationId) +30
System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto) +699
System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading) +562
System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId) +404
System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration) +447
System.Data.Entity.Migrations.<>c__DisplayClassc.<Update>b__b() +13
System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) +422
System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) +78
System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext) +89
System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState) +116
System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) +218
System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +151
System.Data.Entity.Internal.<>c__DisplayClassf`1.<CreateInitializationAction>b__e() +76
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +60
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +357
System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) +7
System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +110
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +198
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +73
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +28
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +53
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +38
System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(IQueryable`1 source, Expression`1 predicate, CancellationToken cancellationToken) +138
System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(IQueryable`1 source, Expression`1 predicate) +145
Microsoft.AspNet.Identity.EntityFramework.<GetUserAggregateAsync>d__6c.MoveNext() +498
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
Microsoft.AspNet.Identity.CultureAwaiter`1.GetResult() +59
Microsoft.AspNet.Identity.Owin.<PasswordSignInAsync>d__29.MoveNext() +354
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
WebApplication1.Controllers.<Login>d__11.MoveNext() in C:\Users\TAMBARIN\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1\Controllers\AccountController.cs:79
解决方案
所以基本上为了避免这个问题,我只是告诉实体框架不要使用这个来创建序列:
modelBuilder.Entity<ApplicationUser>().Property(p => p.Id).HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None);
所以他不会尝试自动递增主键,也不需要创建序列
推荐阅读
- angular - Angular 路由在生产中不起作用(aruba 托管)
- google-chrome-extension - 带有苗条 devtools 的电子应用程序没有检测到我的苗条
- django - Django中的自定义主键
- flutter - 启用空安全后,如何初始化一个空文件而不给它一个颤振的路径
- reactjs - 使用 node.js 的 Cloudinary 上传图片和视频需要太多时间
- javascript - 有什么方法可以替换 Javascript 中已弃用的 CustomEvent.initCustomEvent() 吗?
- javascript - 如何将 jQuery 函数转换为 JavaScript?
- r - 理解断点函数:for 循环如何在函数内部工作
- asp.net-web-api - 当 ApiController.cs 文件中包含 iTextSharp 命名空间时,ASP.Net Web API 返回 500 内部服务器错误
- python - 如何替换列表中的字母?