SignInManager.PasswordSignInAsync generate many database access : <p>In my application, I use ASP.NET Identity. Every thing is work fine but by testing, I found that the following command produces many database accesses:
SignInManager.PasswordSignInAsync:</p>

<pre><code>var result = await SignInManager.PasswordSignInAsync(user.UserName, model.Password, model.RememberMe, shouldLockout: true);
</code></pre>

<p>I notice this problem when testing the application using performance test. The test shows that the login request needs huge time to get response. The following figure shows result of performance test for the login request:
<a href="https://i.stack.imgur.com/Tq05m.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/Tq05m.jpg" alt="enter image description here"></a>.</p>

<p>Then I use SQL Server Profiler to check what happen when the command SignInManager.PasswordSignInAsync is executed. It shows that a lot of database accesses is generated. The following is taken from SQL Server Profiler:</p>

<pre><code>exec sp_executesql N'SELECT TOP (1) 
    [Extent1].[Id] AS [Id], 
    [Extent1].[UserFullName] AS [UserFullName], 
    [Extent1].[UserId] AS [UserId], 
    [Extent1].[Online] AS [Online], 
    [Extent1].[LastOnlineDate] AS [LastOnlineDate], 
    [Extent1].[BrithDate] AS [BrithDate], 
    [Extent1].[Job] AS [Job], 
    [Extent1].[Gender] AS [Gender], 
    [Extent1].[CountryId] AS [CountryId], 
    [Extent1].[LivesIn] AS [LivesIn], 
    [Extent1].[RelationId] AS [RelationId], 
    [Extent1].[Religion] AS [Religion], 
    [Extent1].[FirstSchool] AS [FirstSchool], 
    [Extent1].[SecondSchool] AS [SecondSchool], 
    [Extent1].[University] AS [University], 
    [Extent1].[ContactInfo] AS [ContactInfo], 
    [Extent1].[Email] AS [Email], 
    [Extent1].[EmailConfirmed] AS [EmailConfirmed], 
    [Extent1].[PasswordHash] AS [PasswordHash], 
    [Extent1].[SecurityStamp] AS [SecurityStamp], 
    [Extent1].[PhoneNumber] AS [PhoneNumber], 
    [Extent1].[PhoneNumberConfirmed] AS [PhoneNumberConfirmed], 
    [Extent1].[TwoFactorEnabled] AS [TwoFactorEnabled], 
    [Extent1].[LockoutEndDateUtc] AS [LockoutEndDateUtc], 
    [Extent1].[LockoutEnabled] AS [LockoutEnabled], 
    [Extent1].[AccessFailedCount] AS [AccessFailedCount], 
    [Extent1].[UserName] AS [UserName]
    FROM [dbo].[AspNetUsers] AS [Extent1]
    WHERE ((UPPER([Extent1].[UserName])) = (UPPER(@p__linq__0))) OR ((UPPER([Extent1].[UserName]) IS NULL) AND (UPPER(@p__linq__0) IS NULL))',N'@p__linq__0 nvarchar(4000)',@p__linq__0=N'User1@gmail.com'

exec sp_executesql N'SELECT 
    [Extent1].[Id] AS [Id], 
    [Extent1].[UserId] AS [UserId], 
    [Extent1].[ClaimType] AS [ClaimType], 
    [Extent1].[ClaimValue] AS [ClaimValue]
    FROM [dbo].[AspNetUserClaims] AS [Extent1]
    WHERE [Extent1].[UserId] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103

exec sp_executesql N'SELECT 
    [Extent1].[Id] AS [Id], 
    [Extent1].[UserId] AS [UserId], 
    [Extent1].[ClaimType] AS [ClaimType], 
    [Extent1].[ClaimValue] AS [ClaimValue]
    FROM [dbo].[AspNetUserClaims] AS [Extent1]
    WHERE [Extent1].[UserId] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103

exec sp_executesql N'SELECT 
    [Extent1].[LoginProvider] AS [LoginProvider], 
    [Extent1].[ProviderKey] AS [ProviderKey], 
    [Extent1].[UserId] AS [UserId]
    FROM [dbo].[AspNetUserLogins] AS [Extent1]
    WHERE [Extent1].[UserId] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103
exec sp_executesql N'SELECT 
    [Extent1].[UserId] AS [UserId], 
    [Extent1].[RoleId] AS [RoleId]
    FROM [dbo].[AspNetUserRoles] AS [Extent1]
    WHERE [Extent1].[UserId] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103
exec sp_executesql N'SELECT TOP (1) 
    [Extent1].[Id] AS [Id], 
    [Extent1].[UserFullName] AS [UserFullName], 
    [Extent1].[UserId] AS [UserId], 
    [Extent1].[Online] AS [Online], 
    [Extent1].[LastOnlineDate] AS [LastOnlineDate], 
    [Extent1].[BrithDate] AS [BrithDate], 
    [Extent1].[Job] AS [Job], 
    [Extent1].[Gender] AS [Gender], 
    [Extent1].[CountryId] AS [CountryId], 
    [Extent1].[LivesIn] AS [LivesIn], 
    [Extent1].[RelationId] AS [RelationId], 
    [Extent1].[Religion] AS [Religion], 
    [Extent1].[FirstSchool] AS [FirstSchool], 
    [Extent1].[SecondSchool] AS [SecondSchool], 
    [Extent1].[University] AS [University], 
    [Extent1].[ContactInfo] AS [ContactInfo], 
    [Extent1].[Email] AS [Email], 
    [Extent1].[EmailConfirmed] AS [EmailConfirmed], 
    [Extent1].[PasswordHash] AS [PasswordHash], 
    [Extent1].[SecurityStamp] AS [SecurityStamp], 
    [Extent1].[PhoneNumber] AS [PhoneNumber], 
    [Extent1].[PhoneNumberConfirmed] AS [PhoneNumberConfirmed], 
    [Extent1].[TwoFactorEnabled] AS [TwoFactorEnabled], 
    [Extent1].[LockoutEndDateUtc] AS [LockoutEndDateUtc], 
    [Extent1].[LockoutEnabled] AS [LockoutEnabled], 
    [Extent1].[AccessFailedCount] AS [AccessFailedCount], 
    [Extent1].[UserName] AS [UserName]
    FROM [dbo].[AspNetUsers] AS [Extent1]
    WHERE [Extent1].[Id] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103
exec sp_executesql N'SELECT 
    [Extent1].[Id] AS [Id], 
    [Extent1].[UserId] AS [UserId], 
    [Extent1].[ClaimType] AS [ClaimType], 
    [Extent1].[ClaimValue] AS [ClaimValue]
    FROM [dbo].[AspNetUserClaims] AS [Extent1]
    WHERE [Extent1].[UserId] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103
exec sp_executesql N'SELECT 
    [Extent1].[LoginProvider] AS [LoginProvider], 
    [Extent1].[ProviderKey] AS [ProviderKey], 
    [Extent1].[UserId] AS [UserId]
    FROM [dbo].[AspNetUserLogins] AS [Extent1]
    WHERE [Extent1].[UserId] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103

    exec sp_executesql N'SELECT 
        [Extent1].[UserId] AS [UserId], 
        [Extent1].[RoleId] AS [RoleId]
        FROM [dbo].[AspNetUserRoles] AS [Extent1]
        WHERE [Extent1].[UserId] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103
    exec sp_executesql N'SELECT TOP (1) 
        [Extent1].[Id] AS [Id], 
        [Extent1].[UserFullName] AS [UserFullName], 
        [Extent1].[UserId] AS [UserId], 
        [Extent1].[Online] AS [Online], 
        [Extent1].[LastOnlineDate] AS [LastOnlineDate], 
        [Extent1].[BrithDate] AS [BrithDate], 
        [Extent1].[Job] AS [Job], 
        [Extent1].[Gender] AS [Gender], 
        [Extent1].[CountryId] AS [CountryId], 
        [Extent1].[LivesIn] AS [LivesIn], 
        [Extent1].[RelationId] AS [RelationId], 
        [Extent1].[Religion] AS [Religion], 
        [Extent1].[FirstSchool] AS [FirstSchool], 
        [Extent1].[SecondSchool] AS [SecondSchool], 
        [Extent1].[University] AS [University], 
        [Extent1].[ContactInfo] AS [ContactInfo], 
        [Extent1].[Email] AS [Email], 
        [Extent1].[EmailConfirmed] AS [EmailConfirmed], 
        [Extent1].[PasswordHash] AS [PasswordHash], 
        [Extent1].[SecurityStamp] AS [SecurityStamp], 
        [Extent1].[PhoneNumber] AS [PhoneNumber], 
        [Extent1].[PhoneNumberConfirmed] AS [PhoneNumberConfirmed], 
        [Extent1].[TwoFactorEnabled] AS [TwoFactorEnabled], 
        [Extent1].[LockoutEndDateUtc] AS [LockoutEndDateUtc], 
        [Extent1].[LockoutEnabled] AS [LockoutEnabled], 
        [Extent1].[AccessFailedCount] AS [AccessFailedCount], 
        [Extent1].[UserName] AS [UserName]
        FROM [dbo].[AspNetUsers] AS [Extent1]
        WHERE [Extent1].[Id] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103
    exec sp_executesql N'SELECT 
        [Extent1].[Id] AS [Id], 
        [Extent1].[UserId] AS [UserId], 
        [Extent1].[ClaimType] AS [ClaimType], 
        [Extent1].[ClaimValue] AS [ClaimValue]
        FROM [dbo].[AspNetUserClaims] AS [Extent1]
        WHERE [Extent1].[UserId] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103
exec sp_executesql N'SELECT 
    [Extent1].[LoginProvider] AS [LoginProvider], 
    [Extent1].[ProviderKey] AS [ProviderKey], 
    [Extent1].[UserId] AS [UserId]
    FROM [dbo].[AspNetUserLogins] AS [Extent1]
    WHERE [Extent1].[UserId] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103
exec sp_executesql N'SELECT 
    [Extent1].[UserId] AS [UserId], 
    [Extent1].[RoleId] AS [RoleId]
    FROM [dbo].[AspNetUserRoles] AS [Extent1]
    WHERE [Extent1].[UserId] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103
exec sp_executesql N'SELECT TOP (1) 
    [Extent1].[Id] AS [Id], 
    [Extent1].[UserFullName] AS [UserFullName], 
    [Extent1].[UserId] AS [UserId], 
    [Extent1].[Online] AS [Online], 
    [Extent1].[LastOnlineDate] AS [LastOnlineDate], 
    [Extent1].[BrithDate] AS [BrithDate], 
    [Extent1].[Job] AS [Job], 
    [Extent1].[Gender] AS [Gender], 
    [Extent1].[CountryId] AS [CountryId], 
    [Extent1].[LivesIn] AS [LivesIn], 
    [Extent1].[RelationId] AS [RelationId], 
    [Extent1].[Religion] AS [Religion], 
    [Extent1].[FirstSchool] AS [FirstSchool], 
    [Extent1].[SecondSchool] AS [SecondSchool], 
    [Extent1].[University] AS [University], 
    [Extent1].[ContactInfo] AS [ContactInfo], 
    [Extent1].[Email] AS [Email], 
    [Extent1].[EmailConfirmed] AS [EmailConfirmed], 
    [Extent1].[PasswordHash] AS [PasswordHash], 
    [Extent1].[SecurityStamp] AS [SecurityStamp], 
    [Extent1].[PhoneNumber] AS [PhoneNumber], 
    [Extent1].[PhoneNumberConfirmed] AS [PhoneNumberConfirmed], 
    [Extent1].[TwoFactorEnabled] AS [TwoFactorEnabled], 
    [Extent1].[LockoutEndDateUtc] AS [LockoutEndDateUtc], 
    [Extent1].[LockoutEnabled] AS [LockoutEnabled], 
    [Extent1].[AccessFailedCount] AS [AccessFailedCount], 
    [Extent1].[UserName] AS [UserName]
    FROM [dbo].[AspNetUsers] AS [Extent1]
    WHERE [Extent1].[Id] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103
exec sp_executesql N'SELECT 
    [Extent1].[Id] AS [Id], 
    [Extent1].[UserId] AS [UserId], 
    [Extent1].[ClaimType] AS [ClaimType], 
    [Extent1].[ClaimValue] AS [ClaimValue]
    FROM [dbo].[AspNetUserClaims] AS [Extent1]
    WHERE [Extent1].[UserId] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=2103
</code></pre>

<p>The above queries are just a part of the result. The same queries are executed several times. Is this the normal case or there is a problem ?</p>

<p>If it is a problem, how it can be solved.</p>
