SqlException:无效的列名称'NormalizedUserName'

时间:2019-08-14 14:05:11

标签: .net-core identity

我使用的是dotnet core 2.2,我的当前站点是很久以前用Webforms编写的SQL成员身份。我在这里Migration Link

遵循了Microsoft提供的说明。

现在,当我测试登录名时,会收到以下错误消息。 该数据库确实具有以下错误消息提示它没有的所有字段。还包括这些模型,以便您了解它们的编写方式。

public class AspNetRoles
{
    public AspNetRoles()
    {
        AspNetRoleClaims = new HashSet<AspNetRoleClaims>();
        AspNetUserRoles = new HashSet<AspNetUserRoles>();
    }

    public string Id { get; set; }
    public string Name { get; set; }
    public string NormalizedName { get; set; }
    public string ConcurrencyStamp { get; set; }

    public virtual ICollection<AspNetRoleClaims> AspNetRoleClaims { get; set; }
    public virtual ICollection<AspNetUserRoles> AspNetUserRoles { get; set; }
}



public class AspNetUserLogins
{
    public string LoginProvider { get; set; }
    public string ProviderKey { get; set; }
    public string ProviderDisplayName { get; set; }
    public string UserId { get; set; }

    public virtual AspNetUsers User { get; set; }
}



public class Profiles : IdentityUser
    {
        public string Id { get; set; }
        public int LegacyClientId { get; set; }
        public string UserId { get; set; }
        //public string UserName { get; set; }
        public string Address { get; set; }
        public string Address2 { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string Zip { get; set; }
        public string AgencyName { get; set; }
        public string ContactName { get; set; }
        public string ContactPhone { get; set; }
        public string Region { get; set; }

        public virtual AspNetUsers User { get; set; }
    }


public class AspNetUsers
    {
        public AspNetUsers()
        {
            AspNetUserClaims = new HashSet<AspNetUserClaims>();
            AspNetUserLogins = new HashSet<AspNetUserLogins>();
            AspNetUserRoles = new HashSet<AspNetUserRoles>();
            AspNetUserTokens = new HashSet<AspNetUserTokens>();
            Profiles = new HashSet<Profiles>();
            Uploads = new HashSet<Uploads>();
        }

        public string Id { get; set; }
        public string UserName { get; set; }
        public string NormalizedUserName { get; set; }
        public string Email { get; set; }
        public string NormalizedEmail { get; set; }
        public bool EmailConfirmed { get; set; }
        public string PasswordHash { get; set; }
        public string SecurityStamp { get; set; }
        public string ConcurrencyStamp { get; set; }
        public string PhoneNumber { get; set; }
        public bool PhoneNumberConfirmed { get; set; }
        public bool TwoFactorEnabled { get; set; }
        public DateTimeOffset? LockoutEnd { get; set; }
        public bool LockoutEnabled { get; set; }
        public int AccessFailedCount { get; set; }

        public virtual ICollection<AspNetUserClaims> AspNetUserClaims { get; set; }
        public virtual ICollection<AspNetUserLogins> AspNetUserLogins { get; set; }
        public virtual ICollection<AspNetUserRoles> AspNetUserRoles { get; set; }
        public virtual ICollection<AspNetUserTokens> AspNetUserTokens { get; set; }
        public virtual ICollection<Profiles> Profiles { get; set; }
        public virtual ICollection<Uploads> Uploads { get; set; }
    }

这是我得到的完整错误

  

SqlException: Invalid column name 'NormalizedUserName'.
 Invalid column name 'AccessFailedCount'.
 Invalid column name 'ConcurrencyStamp'.
 Invalid column name 'Email'.
 Invalid column name 'EmailConfirmed'.
 Invalid column name 'LockoutEnabled'.
 Invalid column name 'LockoutEnd'.
 Invalid column name 'NormalizedEmail'.
 Invalid column name 'NormalizedUserName'.
 Invalid column name 'PasswordHash'.
 Invalid column name 'PhoneNumber'.
 Invalid column name 'PhoneNumberConfirmed'.
 Invalid column name 'SecurityStamp'.
 Invalid column name 'TwoFactorEnabled'.
System.Data.SqlClient.SqlCommand+<>c.<ExecuteDbDataReaderAsync>b__122_0(Task<SqlDataReader> result)
System.Threading.Tasks.ContinuationResultTaskFromResultTask<TAntecedentResult, TResult>.InnerInvoke()
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, object state)
System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref Task currentTaskSlot)
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteAsync(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary<string, object> parameterValues, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable<T>+AsyncEnumerator.BufferlessMoveNext(DbContext _, bool buffer, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync<TState, TResult>(TState state, Func<DbContext, TState, CancellationToken, Task<TResult>> operation, Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>> verifySucceeded, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable<T>+AsyncEnumerator.MoveNext(CancellationToken cancellationToken)
System.Linq.AsyncEnumerable.FirstOrDefault_<TSource>(IAsyncEnumerable<TSource> source, CancellationToken cancellationToken) in First.cs
Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider+TaskResultAsyncEnumerable<T>+Enumerator.MoveNext(CancellationToken cancellationToken)
System.Linq.AsyncEnumerable+SelectEnumerableAsyncIterator<TSource, TResult>.MoveNextCore(CancellationToken cancellationToken) in Select.cs
System.Linq.AsyncEnumerable+AsyncIterator<TSource>.MoveNext(CancellationToken cancellationToken) in AsyncIterator.cs
Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider+ExceptionInterceptor<T>+EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteSingletonAsyncQuery<TResult>(QueryContext queryContext, Func<QueryContext, IAsyncEnumerable<TResult>> compiledQuery, IDiagnosticsLogger<Query> logger, Type contextType)
Microsoft.AspNetCore.Identity.UserManager<TUser>.FindByNameAsync(string userName)
MyProject.Tester.WebAPI.Controllers.Security.AuthController.GetClaimsIdentity(string userName, string password) in AuthController.cs
+
        private async Task<ClaimsIdentity> GetClaimsIdentity(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
                return await Task.FromResult<ClaimsIdentity>(null);
            // get the user to verifty
            var userToVerify = await _userManager.FindByNameAsync(userName);
            if (userToVerify == null) return await Task.FromResult<ClaimsIdentity>(null);
            // check the credentials
            if (await _userManager.CheckPasswordAsync(userToVerify, password))
            {
MyProject.Tester.WebAPI.Controllers.Security.AuthController.LoginAsync(LoginModel user) in AuthController.cs
+
        // GET api/values
        [HttpPost, Route("login")]
        [AllowAnonymous]
        public async Task<IActionResult> LoginAsync([FromBody]LoginModel user)
        {
            var identity = await GetClaimsIdentity(user.UserName, user.Password);
            if (identity == null)
            {
                return BadRequest(Errors.AddErrorToModelState("login_failure", "Invalid username or password.", ModelState));
            }
Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask<TResult>.get_Result()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

0 个答案:

没有答案