Skip to content

Commit

Permalink
fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
ili committed Jul 6, 2017
1 parent eb3663b commit 66373fb
Show file tree
Hide file tree
Showing 2 changed files with 326 additions and 96 deletions.
26 changes: 22 additions & 4 deletions src/LinqToDB.Identity/RoleStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,20 @@ public Task SetRoleNameAsync(TRole role, string roleName,
/// should be canceled.
/// </param>
/// <returns>A <see cref="Task{TResult}" /> that result of the look up.</returns>
public virtual Task<TRole> FindByIdAsync(string id, CancellationToken cancellationToken = default(CancellationToken))
public async Task<TRole> FindByIdAsync(string id, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
var roleId = ConvertIdFromString(id);
return Roles.FirstOrDefaultAsync(u => u.Id.Equals(roleId), cancellationToken);

using (var db = GetConnection())
return await FindByIdAsync(db, roleId, cancellationToken);
}

/// <inheritdoc cref="FindByIdAsync(string, CancellationToken)"/>
protected virtual async Task<TRole> FindByIdAsync(DataConnection db, TKey roleId, CancellationToken cancellationToken)
{
return await db.GetTable<TRole>().FirstOrDefaultAsync(u => u.Id.Equals(roleId), cancellationToken);
}

/// <summary>
Expand All @@ -295,12 +303,22 @@ public Task SetRoleNameAsync(TRole role, string roleName,
/// should be canceled.
/// </param>
/// <returns>A <see cref="Task{TResult}" /> that result of the look up.</returns>
public virtual Task<TRole> FindByNameAsync(string normalizedName,
public async Task<TRole> FindByNameAsync(string normalizedName,
CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
return Roles.FirstOrDefaultAsync(r => r.NormalizedName == normalizedName, cancellationToken);
using (var db = GetConnection())
{
return await FindByNameAsync(db, normalizedName, cancellationToken);
}

}

/// <inheritdoc cref="FindByNameAsync(string, CancellationToken)"/>
protected virtual async Task<TRole> FindByNameAsync(DataConnection db, string normalizedName, CancellationToken cancellationToken)
{
return await db.GetTable<TRole>().FirstOrDefaultAsync(r => r.NormalizedName == normalizedName, cancellationToken);
}

/// <summary>
Expand Down
Loading

0 comments on commit 66373fb

Please sign in to comment.