dotnet / dotnet/aspnetcore

Identity `UserManager.UpdateAsync()` method is not efficient.

Open
#32,933 1 comment 0 reactions 0 assignees View on GitHub
area-identity bug
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

EF Core update command for a tracked entity only generates the update command for the modified fields only and if no field is modified then it does not send any update command to the database. This is a pretty much efficient approach. We love it.

However, although ASP.NET Core Identity heavily depends on EF Core, `UserManager.UpdateAsync()` generating an update command for all the fields for the identity user. Even though no field is changed it's sending an update command to the database with all the fields. This is pretty much annoying and costlier. Also goes against EF Core motivation.

For say, I have changed UserName of the IdentityUser:

**EF Core Generated Command:**

```SQL
UPDATE "AspNetUsers" SET "UserName" = @p0
WHERE "Id" = @p1 AND "ConcurrencyStamp" = @p2;
```
**ASP.NET Core Identity Generated Command**:

```SQL
UPDATE "AspNetUsers" SET "AccessFailedCount" = @p0, "ConcurrencyStamp" = @p1, "CountryId" = @p2, "DateOfBirth" = @p3, "Email" = @p4, "EmailConfirmed" = @p5, "FirstName" = @p6, "Gender" = @p7, "Language" = @p8, "LastName" = @p9, "LockoutEnabled" = @p10, "LockoutEnd" = @p11, "NormalizedEmail" = @p12, "NormalizedUserName" = @p13, "PasswordHash" = @p14, "PhoneNumber" = @p15, "PhoneNumberConfirmed" = @p16, "PhotoUrl" = @p17, "PostCode" = @p18, "ReferredBy" = @p19, "RefreshToken" = @p20, "SecurityPin" = @p21, "SecurityStamp" = @p22, "Theme" = @p23, "TwoFactorEnabled" = @p24, "UserName" = @p25
WHERE "Id" = @p26 AND "ConcurrencyStamp" = @p27;
```

Please fix this.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.