Skip to content

EF trying to Insert into Identity field #6426

@Dethorhyne

Description

@Dethorhyne

Steps to reproduce

  1. Make a new solution, add NumericId to the ApplicationUser class and make it look like this:
public class ApplicationUser : IdentityUser
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public virtual int NumericId { get; set; }
}
  1. Execute UserManager.UpdateAsync(user);
  2. Witness the error

The issue

For some reason EF is attempting to insert value into an Identity column which isn't allowed and throws an exception. Rest of the columns do NOT get updated.

However,
this bug also accured when I tried to register, but in that case, database wise, everything was Inserted, new user was registered and a proper NumericId was assigned to the user even though the front-end threw the exception. Few builds after, even though nothing has changed, registering stopped throwing the exception and functions properly.

Exception message:

SqlException: Cannot update identity column 'NumericId'.
MoveNext

DbUpdateException: An error occurred while updating the entries. See the inner exception for details.
MoveNext

Stack trace:
System.Data.SqlClient.SqlException: Cannot update identity column 'NumericId'.
   at System.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__107_0(Task`1 result)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.<ExecuteAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.<ExecuteAsync>d__32.MoveNext()
ClientConnectionId:5be684a0-2aee-4a9f-ac8b-9d4bcea49b47
Error Number:8102,State:1,Class:16

Further technical details

EF Core version: 1.0.0
Operating system: Windows 7 Professional
Visual Studio version: VS 2015 Enterprise edition

Other details about my project setup:
None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions