对于项目,我正在尝试使用身份作为身份验证服务。为此,我试图将实体映射到现有数据库。我认为这部分已经完成并且现在正在工作,但是当我尝试登录时,会出现错误并且我不知道如何修复它。
据说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
答案 0 :(得分:0)
所以基本上要避免这个问题,我只是告诉实体框架不要使用这个创建序列:
modelBuilder.Entity<ApplicationUser>().Property(p => p.Id).HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None);
所以他不会尝试自动增加主键,也不需要创建序列