Add OrderBy top the first/firstordefault operator

pull/6396/head
liangshiwei 5 years ago
parent f6ecd5d71e
commit 4b7a499303

@ -144,6 +144,7 @@ namespace Volo.Abp.AuditLogging.MongoDB
public virtual async Task<EntityChange> GetEntityChange(Guid entityChangeId)
{
var entityChange = (await GetMongoQueryable()
.OrderBy(x => x.Id)
.Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId))
.FirstAsync()).EntityChanges.FirstOrDefault(x => x.Id == entityChangeId);

@ -18,6 +18,7 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore
public virtual async Task<FeatureValue> FindAsync(string name, string providerName, string providerKey)
{
return await DbSet
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(
s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey
);

@ -19,6 +19,7 @@ namespace Volo.Abp.FeatureManagement.MongoDB
public virtual async Task<FeatureValue> FindAsync(string name, string providerName, string providerKey)
{
return await GetMongoQueryable()
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey);
}

@ -80,7 +80,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
public async Task<IdentitySecurityLog> GetByUserIdAsync(Guid id, Guid userId, bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await DbSet.FirstOrDefaultAsync(x => x.Id == id && x.UserId == userId, GetCancellationToken(cancellationToken));
return await DbSet.OrderBy(x => x.Id).FirstOrDefaultAsync(x => x.Id == id && x.UserId == userId, GetCancellationToken(cancellationToken));
}
protected virtual IQueryable<IdentitySecurityLog> GetListQuery(

@ -20,7 +20,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
public async Task<IdentityLinkUser> FindAsync(IdentityLinkUserInfo sourceLinkUserInfo, IdentityLinkUserInfo targetLinkUserInfo, CancellationToken cancellationToken = default)
{
return await DbSet.FirstOrDefaultAsync(x =>
return await DbSet
.OrderBy(x => x.Id).FirstOrDefaultAsync(x =>
x.SourceUserId == sourceLinkUserInfo.UserId && x.SourceTenantId == sourceLinkUserInfo.TenantId &&
x.TargetUserId == targetLinkUserInfo.UserId && x.TargetTenantId == targetLinkUserInfo.TenantId ||
x.TargetUserId == sourceLinkUserInfo.UserId && x.TargetTenantId == sourceLinkUserInfo.TenantId &&

@ -24,6 +24,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{
return await DbSet
.IncludeDetails(includeDetails)
.OrderBy(x => x.NormalizedName)
.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken));
}

@ -80,6 +80,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
return await DbSet
.IncludeDetails(includeDetails)
.Where(u => u.Logins.Any(login => login.LoginProvider == loginProvider && login.ProviderKey == providerKey))
.OrderBy(x=>x.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
@ -112,6 +113,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{
var role = await DbContext.Roles
.Where(x => x.NormalizedName == normalizedRoleName)
.OrderBy(x => x.NormalizedName)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
if (role == null)

@ -75,6 +75,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{
return await DbSet
.IncludeDetails(includeDetails)
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(
ou => ou.DisplayName == displayName,
GetCancellationToken(cancellationToken)

@ -19,7 +19,8 @@ namespace Volo.Abp.Identity.MongoDB
public async Task<IdentityLinkUser> FindAsync(IdentityLinkUserInfo sourceLinkUserInfo, IdentityLinkUserInfo targetLinkUserInfo, CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().FirstOrDefaultAsync(x =>
return await GetMongoQueryable()
.OrderBy(x => x.Id).FirstOrDefaultAsync(x =>
x.SourceUserId == sourceLinkUserInfo.UserId && x.SourceTenantId == sourceLinkUserInfo.TenantId &&
x.TargetUserId == targetLinkUserInfo.UserId && x.TargetTenantId == targetLinkUserInfo.TenantId ||
x.TargetUserId == sourceLinkUserInfo.UserId && x.TargetTenantId == sourceLinkUserInfo.TenantId &&

@ -23,7 +23,9 @@ namespace Volo.Abp.Identity.MongoDB
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken));
return await GetMongoQueryable()
.OrderBy(x => x.NormalizedName)
.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken));
}
public async Task<List<IdentityRole>> GetListAsync(

@ -85,7 +85,7 @@ namespace Volo.Abp.Identity.MongoDB
public async Task<IdentitySecurityLog> GetByUserIdAsync(Guid id, Guid userId, bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().FirstOrDefaultAsync(x => x.Id == id && x.UserId == userId,
return await GetMongoQueryable().OrderBy(x => x.Id).FirstOrDefaultAsync(x => x.Id == id && x.UserId == userId,
GetCancellationToken(cancellationToken));
}

@ -25,6 +25,7 @@ namespace Volo.Abp.Identity.MongoDB
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.OrderBy(x => x.NormalizedUserName)
.FirstOrDefaultAsync(
u => u.NormalizedUserName == normalizedUserName,
GetCancellationToken(cancellationToken)
@ -81,6 +82,7 @@ namespace Volo.Abp.Identity.MongoDB
{
return await GetMongoQueryable()
.Where(u => u.Logins.Any(login => login.LoginProvider == loginProvider && login.ProviderKey == providerKey))
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
@ -89,7 +91,8 @@ namespace Volo.Abp.Identity.MongoDB
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, GetCancellationToken(cancellationToken));
return await GetMongoQueryable()
.OrderBy(x => x.NormalizedEmail).FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<IdentityUser>> GetListByClaimAsync(
@ -107,7 +110,10 @@ namespace Volo.Abp.Identity.MongoDB
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var role = await DbContext.Roles.AsQueryable().Where(x => x.NormalizedName == normalizedRoleName).FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
var role = await DbContext.Roles.AsQueryable()
.Where(x => x.NormalizedName == normalizedRoleName)
.OrderBy(x => x.NormalizedName)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
if (role == null)
{

@ -76,6 +76,7 @@ namespace Volo.Abp.Identity.MongoDB
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(
ou => ou.DisplayName == displayName,
GetCancellationToken(cancellationToken)

@ -20,7 +20,9 @@ namespace Volo.Abp.IdentityServer.ApiScopes
public async Task<ApiScope> GetByNameAsync(string scopeName, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await DbSet.FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken));
return await DbSet
.OrderBy(x=>x.Id)
.FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken));
}
public async Task<List<ApiScope>> GetListByNameAsync(string[] scopeNames, bool includeDetails = false,

@ -25,6 +25,7 @@ namespace Volo.Abp.PermissionManagement.EntityFrameworkCore
CancellationToken cancellationToken = default)
{
return await DbSet
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(s =>
s.Name == name &&
s.ProviderName == providerName &&

@ -25,6 +25,7 @@ namespace Volo.Abp.PermissionManagement.MongoDB
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(s =>
s.Name == name &&
s.ProviderName == providerName &&

@ -18,6 +18,7 @@ namespace Volo.Abp.SettingManagement.EntityFrameworkCore
public virtual async Task<Setting> FindAsync(string name, string providerName, string providerKey)
{
return await DbSet
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(
s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey
);

@ -19,7 +19,7 @@ namespace Volo.Abp.SettingManagement.MongoDB
public virtual async Task<Setting> FindAsync(string name, string providerName, string providerKey)
{
return await GetMongoQueryable().FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey);
return await GetMongoQueryable().OrderBy(x => x.Id).FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey);
}
public virtual async Task<List<Setting>> GetListAsync(string providerName, string providerKey)

@ -22,7 +22,7 @@ namespace Volo.Abp.Users.EntityFrameworkCore
public async Task<TUser> FindByUserNameAsync(string userName, CancellationToken cancellationToken = default)
{
return await this.FirstOrDefaultAsync(u => u.UserName == userName, GetCancellationToken(cancellationToken));
return await this.OrderBy(x => x.UserName).FirstOrDefaultAsync(u => u.UserName == userName, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TUser>> GetListAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default)

@ -23,7 +23,7 @@ namespace Volo.Abp.Users.MongoDB
public virtual async Task<TUser> FindByUserNameAsync(string userName, CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().FirstOrDefaultAsync(u => u.UserName == userName, GetCancellationToken(cancellationToken));
return await GetMongoQueryable().OrderBy(x => x.UserName).FirstOrDefaultAsync(u => u.UserName == userName, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TUser>> GetListAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default)

Loading…
Cancel
Save