.NET Identity UserManager.FindAsyc抛出“无效的列名'Discriminator'". [英] .NET Identity UserManager.FindAsyc throwing "Invalid column name 'Discriminator'."

查看:29
本文介绍了.NET Identity UserManager.FindAsyc抛出“无效的列名'Discriminator'".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的.NET Web应用程序项目,然后为我选择的模板选择个人用户帐户身份验证".默认情况下,这会将Identity数据库设置为App_Data目录中的本地数据库.这很好.但是随后,我需要AspNet表的成员资格位于保存我的其余应用程序的真实SQL Server数据库中.因此,我将DefaultConnection字符串更改为指向我的本地SQL Server数据库,并且当我重新运行该应用程序时,EF会在真实数据库中自动创建这些表.所以一切似乎都很好.

I created a new .NET Web Application project and choose the Individual User Account Authentication for the template I selected. By default this sets up the Identity database to be a local database in the App_Data directory. This worked fine. But then I needed the AspNet tables for membership to be in my real SQL Server database that holds the rest of my application. So I changed the DefaultConnection string to point to my local SQL Server database and when I reran the application, EF automatically created those tables in my real database. So everything seemed good.

然后,当我尝试登录并调用UserManager.FindAsync时,它显示以下SqlException:无效的列名'Discriminator'.".完整的StackTrace如下,以供参考.

Then when I try to Login and it calls UserManager.FindAsync, it gives me the following SqlException: "Invalid column name 'Discriminator'.". The full StackTrace is below for reference.

我使用的是默认Web应用程序模板随附的相同ApplicationDbContext和ApplicationUser.

I'm using the same ApplicationDbContext and ApplicationUser that come with the default web application templates.

任何关于我做错事情的想法吗?这是我第一次使用.NET Identity.除了更改连接字符串之外,还有其他方法可以使它与现有的SQL Server数据库一起工作吗?

Any ideas for what I am doing wrong? This is my first time working with .NET Identity. Is there a different way to make it work with an existing SQL Server database besides just changing the connection string?

谢谢.

完整堆栈跟踪:

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)\r\n   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()\r\n   at System.Data.SqlClient.SqlDataReader.get_MetaData()\r\n   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)\r\n   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)\r\n   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<>c__DisplayClassb.<Reader>b__8()\r\n   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TInterceptionContext,TResult](Func`1 operation, TInterceptionContext interceptionContext, Action`1 executing, Action`1 executed)\r\n   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)\r\n   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)\r\n   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)\r\n   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

推荐答案

两个不同的DbContext?该错误消息可能是由DbContext创建的,类型为IdentityUser的DbSet的数据库引起的,或者更可能是某些与IdentityUser相关的实体.而UserManager似乎正在使用另一个Context(ApplicationDbContext?),其中包含从IdentityUser继承的类型的DbSet.当您的模型实体模型中的某个类型继承自其他类型时,将使用/期望一列称为鉴别符"的列,其中将包含存储在特定行中的实体的类型名称.

Two different DbContexts? The error message could be caused by a database created by a DbContext with a DbSet of type IdentityUser or maybe more likely some entity related to IdentityUser in some way. while the UserManager seems to be using another Context (the ApplicationDbContext?) containing a DbSet of a type inheriting from IdentityUser. When you have a type inheriting from another type in your model entity framework will use/expect a column called discriminator that will contain the type name of the entity that is stored in a particular row.

这篇关于.NET Identity UserManager.FindAsyc抛出“无效的列名'Discriminator'".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆