From af2e3fc9df1270e786df885146c83e2a34e9888c Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 4 Jan 2021 11:16:47 +0800 Subject: [PATCH 1/3] Use async repository method in Blogging module. --- .../Blogging/Blogs/EfCoreBlogRepository.cs | 2 +- .../Comments/EfCoreCommentRepository.cs | 12 ++++++------ .../Blogging/Posts/EfCorePostRepository.cs | 18 +++++++++--------- .../Blogging/Tagging/EfCoreTagRepository.cs | 10 +++++----- .../Volo/Blogging/Blogs/MongoBlogRepository.cs | 2 +- .../Comments/MongoCommentRepository.cs | 8 ++++---- .../Volo/Blogging/Posts/MongoPostRepository.cs | 12 ++++++------ .../Blogging/Tagging/MongoTagRepository.cs | 10 +++++----- .../Blogging/Users/MongoBlogUserRepository.cs | 2 +- 9 files changed, 38 insertions(+), 38 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs index 604f7ca8b5e..564d45dc7ad 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs @@ -17,7 +17,7 @@ public EfCoreBlogRepository(IDbContextProvider dbContextProv public async Task FindByShortNameAsync(string shortName) { - return await DbSet.FirstOrDefaultAsync(p => p.ShortName == shortName); + return await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.ShortName == shortName); } } } diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs index 751d1060717..6c28b521aa1 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs @@ -11,14 +11,14 @@ namespace Volo.Blogging.Comments { public class EfCoreCommentRepository : EfCoreRepository, ICommentRepository { - public EfCoreCommentRepository(IDbContextProvider dbContextProvider) + public EfCoreCommentRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { } public async Task> GetListOfPostAsync(Guid postId) { - return await DbSet + return await (await GetDbSetAsync()) .Where(a => a.PostId == postId) .OrderBy(a => a.CreationTime) .ToListAsync(); @@ -26,20 +26,20 @@ public async Task> GetListOfPostAsync(Guid postId) public async Task GetCommentCountOfPostAsync(Guid postId) { - return await DbSet + return await (await GetDbSetAsync()) .CountAsync(a => a.PostId == postId); } public async Task> GetRepliesOfComment(Guid id) { - return await DbSet + return await (await GetDbSetAsync()) .Where(a => a.RepliedCommentId == id).ToListAsync(); } public async Task DeleteOfPost(Guid id) { - var recordsToDelete = DbSet.Where(pt => pt.PostId == id); - DbSet.RemoveRange(recordsToDelete); + var recordsToDelete = (await GetDbSetAsync()).Where(pt => pt.PostId == id); + (await GetDbSetAsync()).RemoveRange(recordsToDelete); } } } diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs index b152f3ae7df..a5a84fd3406 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs @@ -20,24 +20,24 @@ public EfCorePostRepository(IDbContextProvider dbContextProv public async Task> GetPostsByBlogId(Guid id) { - return await DbSet.Where(p => p.BlogId == id).OrderByDescending(p=>p.CreationTime).ToListAsync(); + return await (await GetDbSetAsync()).Where(p => p.BlogId == id).OrderByDescending(p=>p.CreationTime).ToListAsync(); } - public Task IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null) + public async Task IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null) { - var query = DbSet.Where(p => blogId == p.BlogId && p.Url == url); + var query = (await GetDbSetAsync()).Where(p => blogId == p.BlogId && p.Url == url); if (excludingPostId != null) { query = query.Where(p => excludingPostId != p.Id); } - return query.AnyAsync(); + return await query.AnyAsync(); } public async Task GetPostByUrl(Guid blogId, string url) { - var post = await DbSet.FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url); + var post = await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url); if (post == null) { @@ -51,18 +51,18 @@ public async Task> GetOrderedList(Guid blogId,bool descending = false { if (!descending) { - return await DbSet.Where(x=>x.BlogId==blogId).OrderByDescending(x => x.CreationTime).ToListAsync(); + return await (await GetDbSetAsync()).Where(x=>x.BlogId==blogId).OrderByDescending(x => x.CreationTime).ToListAsync(); } else { - return await DbSet.Where(x => x.BlogId == blogId).OrderBy(x => x.CreationTime).ToListAsync(); + return await (await GetDbSetAsync()).Where(x => x.BlogId == blogId).OrderBy(x => x.CreationTime).ToListAsync(); } } - public override IQueryable WithDetails() + public override async Task> WithDetailsAsync() { - return GetQueryable().IncludeDetails(); + return (await GetQueryableAsync()).IncludeDetails(); } } } diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs index 3e897fa7e3d..a92ae780dad 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs @@ -19,27 +19,27 @@ public EfCoreTagRepository(IDbContextProvider dbContextProvi public async Task> GetListAsync(Guid blogId) { - return await DbSet.Where(t=>t.BlogId == blogId).ToListAsync(); + return await (await GetDbSetAsync()).Where(t=>t.BlogId == blogId).ToListAsync(); } public async Task GetByNameAsync(Guid blogId, string name) { - return await DbSet.FirstAsync(t=> t.BlogId == blogId && t.Name == name); + return await (await GetDbSetAsync()).FirstAsync(t=> t.BlogId == blogId && t.Name == name); } public async Task FindByNameAsync(Guid blogId, string name) { - return await DbSet.FirstOrDefaultAsync(t => t.BlogId == blogId && t.Name == name); + return await (await GetDbSetAsync()).FirstOrDefaultAsync(t => t.BlogId == blogId && t.Name == name); } public async Task> GetListAsync(IEnumerable ids) { - return await DbSet.Where(t => ids.Contains(t.Id)).ToListAsync(); + return await (await GetDbSetAsync()).Where(t => ids.Contains(t.Id)).ToListAsync(); } public async Task DecreaseUsageCountOfTagsAsync(List ids, CancellationToken cancellationToken = default) { - var tags = await DbSet + var tags = await (await GetDbSetAsync()) .Where(t => ids.Any(id => id == t.Id)) .ToListAsync(GetCancellationToken(cancellationToken)); diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs index b1c7b5d319f..6025dfe3cae 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs @@ -15,7 +15,7 @@ public MongoBlogRepository(IMongoDbContextProvider dbCo public async Task FindByShortNameAsync(string shortName) { - return await GetMongoQueryable().FirstOrDefaultAsync(p => p.ShortName == shortName); + return await (await GetMongoQueryableAsync()).FirstOrDefaultAsync(p => p.ShortName == shortName); } } } diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs index b17c7f906f3..bbbe60345b2 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs @@ -17,7 +17,7 @@ public MongoCommentRepository(IMongoDbContextProvider d public async Task> GetListOfPostAsync(Guid postId) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync()) .Where(a => a.PostId == postId) .OrderBy(a => a.CreationTime) .ToListAsync(); @@ -25,19 +25,19 @@ public async Task> GetListOfPostAsync(Guid postId) public async Task GetCommentCountOfPostAsync(Guid postId) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync()) .CountAsync(a => a.PostId == postId); } public async Task> GetRepliesOfComment(Guid id) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync()) .Where(a => a.RepliedCommentId == id).ToListAsync(); } public async Task DeleteOfPost(Guid id) { - var recordsToDelete = GetMongoQueryable().Where(pt => pt.PostId == id); + var recordsToDelete = (await GetMongoQueryableAsync()).Where(pt => pt.PostId == id); foreach (var record in recordsToDelete) { diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs index e12e5f29dee..27f4ad43486 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs @@ -18,25 +18,25 @@ public MongoPostRepository(IMongoDbContextProvider dbCo public async Task> GetPostsByBlogId(Guid id) { - return await GetMongoQueryable().Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync(); + return await (await GetMongoQueryableAsync()).Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync(); } - public Task IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null) + public async Task IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null) { - var query = GetMongoQueryable().Where(p => blogId == p.BlogId && p.Url == url); + var query = (await GetMongoQueryableAsync()).Where(p => blogId == p.BlogId && p.Url == url); if (excludingPostId != null) { query = query.Where(p => excludingPostId != p.Id); } - return query.AnyAsync(); + return await query.AnyAsync(); } public async Task GetPostByUrl(Guid blogId, string url) { - var post = await GetMongoQueryable().FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url); + var post = await (await GetMongoQueryableAsync()).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url); if (post == null) { @@ -48,7 +48,7 @@ public async Task GetPostByUrl(Guid blogId, string url) public async Task> GetOrderedList(Guid blogId, bool @descending = false) { - var query = GetMongoQueryable().Where(x => x.BlogId == blogId); + var query = (await GetMongoQueryableAsync()).Where(x => x.BlogId == blogId); if (!descending) { diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs index 2c0b3b97bf1..f0024b37d7c 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs @@ -20,27 +20,27 @@ public MongoTagRepository(IMongoDbContextProvider dbCon public async Task> GetListAsync(Guid blogId) { - return await GetMongoQueryable().Where(t => t.BlogId == blogId).ToListAsync(); + return await (await GetMongoQueryableAsync()).Where(t => t.BlogId == blogId).ToListAsync(); } public async Task GetByNameAsync(Guid blogId, string name) { - return await GetMongoQueryable().Where(t => t.BlogId == blogId && t.Name == name).FirstAsync(); + return await (await GetMongoQueryableAsync()).Where(t => t.BlogId == blogId && t.Name == name).FirstAsync(); } public async Task FindByNameAsync(Guid blogId, string name) { - return await GetMongoQueryable().Where(t => t.BlogId == blogId && t.Name == name).FirstOrDefaultAsync(); + return await (await GetMongoQueryableAsync()).Where(t => t.BlogId == blogId && t.Name == name).FirstOrDefaultAsync(); } public async Task> GetListAsync(IEnumerable ids) { - return await GetMongoQueryable().Where(t => ids.Contains(t.Id)).ToListAsync(); + return await (await GetMongoQueryableAsync()).Where(t => ids.Contains(t.Id)).ToListAsync(); } public async Task DecreaseUsageCountOfTagsAsync(List ids, CancellationToken cancellationToken = default) { - var tags = await GetMongoQueryable() + var tags = await (await GetMongoQueryableAsync()) .Where(t => ids.Contains(t.Id)) .ToListAsync(GetCancellationToken(cancellationToken)); diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs index a0b7655946e..fdcf4d0097d 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs @@ -17,7 +17,7 @@ public MongoBlogUserRepository(IMongoDbContextProvider public async Task> GetUsersAsync(int maxCount, string filter, CancellationToken cancellationToken) { - var query = GetMongoQueryable(); + var query = await GetMongoQueryableAsync(cancellationToken); if (!string.IsNullOrWhiteSpace(filter)) { From cb38a0fa7439d5e826d3fbedc4bb7405a572090e Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 4 Jan 2021 11:29:36 +0800 Subject: [PATCH 2/3] Use async repository method in CmsKit module. --- .../Volo/CmsKit/Comments/EfCoreCommentRepository.cs | 6 +++--- .../Volo/CmsKit/Pages/EfCorePageRepository.cs | 6 +++--- .../Volo/CmsKit/Ratings/EfCoreRatingRepository.cs | 6 +++--- .../CmsKit/Reactions/EfCoreUserReactionRepository.cs | 6 +++--- .../Volo/CmsKit/Tags/EfCoreTagRepository.cs | 8 ++++---- .../CmsKit/MongoDB/Comments/MongoCommentRepository.cs | 8 ++++---- .../Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs | 8 ++++---- .../CmsKit/MongoDB/Ratings/MongoRatingRepository.cs | 6 +++--- .../MongoDB/Reactions/MongoUserReactionRepository.cs | 6 +++--- .../Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs | 10 +++++----- 10 files changed, 35 insertions(+), 35 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs index 9dec7877f8a..40496aaef86 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs @@ -28,8 +28,8 @@ public async Task> GetListWithAuthorsAsyn Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); - var query = from comment in DbSet - join user in DbContext.Set() on comment.CreatorId equals user.Id + var query = from comment in (await GetDbSetAsync()) + join user in (await GetDbContextAsync()).Set() on comment.CreatorId equals user.Id where entityType == comment.EntityType && entityId == comment.EntityId orderby comment.CreationTime select new CommentWithAuthorQueryResultItem @@ -45,7 +45,7 @@ public async Task DeleteWithRepliesAsync( Comment comment, CancellationToken cancellationToken = default) { - var replies = await DbSet + var replies = await (await GetDbSetAsync()) .Where(x => x.RepliedCommentId == comment.Id) .ToListAsync(GetCancellationToken(cancellationToken)); diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs index 4502a13b4c7..93a7df00d29 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs @@ -23,9 +23,9 @@ public Task FindByUrlAsync(string url) return FindAsync(x => x.Url == url); } - public Task DoesExistAsync(string url) + public async Task DoesExistAsync(string url) { - return DbSet.AnyAsync(x => x.Url == url); + return await (await GetDbSetAsync()).AnyAsync(x => x.Url == url); } } -} \ No newline at end of file +} diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Ratings/EfCoreRatingRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Ratings/EfCoreRatingRepository.cs index 810335b4d60..a48c288932e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Ratings/EfCoreRatingRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Ratings/EfCoreRatingRepository.cs @@ -24,7 +24,7 @@ public async Task GetCurrentUserRatingAsync(string entityType, string en Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); - var rating = await DbSet.FirstOrDefaultAsync( + var rating = await (await GetDbSetAsync()).FirstOrDefaultAsync( r => r.EntityType == entityType && r.EntityId == entityId && r.CreatorId == userId, GetCancellationToken(cancellationToken)); @@ -38,7 +38,7 @@ public async Task> GetGroupedStarCounts Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); var query = ( - from rating in DbSet + from rating in (await GetDbSetAsync()) where rating.EntityType == entityType && rating.EntityId == entityId group rating by rating.StarCount into g @@ -54,4 +54,4 @@ into g return ratings; } } -} \ No newline at end of file +} diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Reactions/EfCoreUserReactionRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Reactions/EfCoreUserReactionRepository.cs index da89de4c74d..65824c79b66 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Reactions/EfCoreUserReactionRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Reactions/EfCoreUserReactionRepository.cs @@ -30,7 +30,7 @@ public async Task FindAsync( Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); Check.NotNullOrWhiteSpace(reactionName, nameof(reactionName)); - return await DbSet + return await (await GetDbSetAsync()) .Where(x => x.CreatorId == userId && x.EntityType == entityType && @@ -48,7 +48,7 @@ public async Task> GetListForUserAsync( Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); - return await DbSet + return await (await GetDbSetAsync()) .Where(x => x.CreatorId == userId && x.EntityType == entityType && @@ -64,7 +64,7 @@ public async Task> GetSummariesAsync( Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); - return await DbSet + return await (await GetDbSetAsync()) .Where(x => x.EntityType == entityType && x.EntityId == entityId) diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs index 0b6cfe1f48d..3d917a059a2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs @@ -19,13 +19,13 @@ public EfCoreTagRepository(IDbContextProvider dbContextProvide { } - public virtual Task AnyAsync( + public virtual async Task AnyAsync( [NotNull] string entityType, [NotNull] string name, Guid? tenantId = null, CancellationToken cancellationToken = default) { - return DbSet.AnyAsync(x => + return await (await GetDbSetAsync()).AnyAsync(x => x.EntityType == entityType && x.Name == name && x.TenantId == tenantId, @@ -64,12 +64,12 @@ public virtual async Task> GetAllRelatedTagsAsync( Guid? tenantId = null, CancellationToken cancellationToken = default) { - var entityTagIds = await DbContext.Set() + var entityTagIds = await (await GetDbContextAsync()).Set() .Where(q => q.EntityId == entityId && q.TenantId == tenantId) .Select(q => q.TagId) .ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); - var query = DbSet + var query = (await GetDbSetAsync()) .Where(x => x.EntityType == entityType && x.TenantId == tenantId && entityTagIds.Contains(x.Id)); diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs index 9564bcf9f83..5d16c6d55c5 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs @@ -26,15 +26,15 @@ public async Task> GetListWithAuthorsAsyn Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); - var authorsQuery = from comment in GetMongoQueryable() - join user in DbContext.CmsUsers on comment.CreatorId equals user.Id + var authorsQuery = from comment in (await GetMongoQueryableAsync(cancellationToken)) + join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id where entityType == comment.EntityType && entityId == comment.EntityId orderby comment.CreationTime select user; var authors = await authorsQuery.ToListAsync(GetCancellationToken(cancellationToken)); - var comments = await GetMongoQueryable() + var comments = await (await GetMongoQueryableAsync(cancellationToken)) .Where(c => c.EntityId == entityId && c.EntityType == entityType) .OrderBy(c => c.CreationTime) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -53,7 +53,7 @@ public async Task DeleteWithRepliesAsync( Comment comment, CancellationToken cancellationToken = default) { - var replies = await GetMongoQueryable() + var replies = await (await GetMongoQueryableAsync(cancellationToken)) .Where(x => x.RepliedCommentId == comment.Id) .ToListAsync(GetCancellationToken(cancellationToken)); diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs index e7c6cd32f50..8537500c96c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs @@ -22,10 +22,10 @@ public Task FindByUrlAsync(string url) { return FindAsync(x => x.Url == url); } - - public Task DoesExistAsync(string url) + + public async Task DoesExistAsync(string url) { - return GetMongoQueryable().AnyAsync(x => x.Url == url); + return await (await GetMongoQueryableAsync()).AnyAsync(x => x.Url == url); } } -} \ No newline at end of file +} diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs index 92f7f992da6..8ff8b4f81d2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs @@ -25,7 +25,7 @@ public async Task GetCurrentUserRatingAsync(string entityType, string en Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); - var rating = await GetMongoQueryable() + var rating = await (await GetMongoQueryableAsync(cancellationToken)) .FirstOrDefaultAsync(r => r.EntityType == entityType && r.EntityId == entityId && r.CreatorId == userId, GetCancellationToken(cancellationToken)); @@ -39,7 +39,7 @@ public async Task> GetGroupedStarCounts Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); var query = ( - from rating in GetMongoQueryable() + from rating in (await GetMongoQueryableAsync(cancellationToken)) where rating.EntityType == entityType && rating.EntityId == entityId group rating by rating.StarCount into g @@ -55,4 +55,4 @@ into g return ratings; } } -} \ No newline at end of file +} diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Reactions/MongoUserReactionRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Reactions/MongoUserReactionRepository.cs index e3a09c45140..6ac4cf1b80e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Reactions/MongoUserReactionRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Reactions/MongoUserReactionRepository.cs @@ -29,7 +29,7 @@ public async Task FindAsync( Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); Check.NotNullOrWhiteSpace(reactionName, nameof(reactionName)); - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .Where(x => x.CreatorId == userId && x.EntityType == entityType && @@ -47,7 +47,7 @@ public async Task> GetListForUserAsync( Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .Where(x => x.CreatorId == userId && x.EntityType == entityType && @@ -63,7 +63,7 @@ public async Task> GetSummariesAsync( Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .Where(x => x.EntityType == entityType && x.EntityId == entityId) diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs index 86dc20d83c3..02c42c22fbd 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs @@ -18,13 +18,13 @@ public MongoTagRepository(IMongoDbContextProvider dbConte { } - public Task AnyAsync( + public async Task AnyAsync( [NotNull] string entityType, [NotNull] string name, Guid? tenantId = null, CancellationToken cancellationToken = default) { - return GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .AnyAsync(x => x.EntityType == entityType && x.Name == name && @@ -64,13 +64,13 @@ public virtual async Task> GetAllRelatedTagsAsync( Guid? tenantId = null, CancellationToken cancellationToken = default) { - var entityTagIds = await DbContext.EntityTags.AsQueryable() + var entityTagIds = await (await GetDbContextAsync(cancellationToken)).EntityTags.AsQueryable() .Where(q => q.EntityId == entityId && q.TenantId == tenantId) .Select(q => q.TagId) .ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); - var query = GetMongoQueryable() - .Where(x => + var query = (await GetMongoQueryableAsync(cancellationToken)) + .Where(x => x.EntityType == entityType && x.TenantId == tenantId && entityTagIds.Contains(x.Id)); From 4924b016a9c3b2e31f3c30318e21e2ad6d19e1d7 Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 4 Jan 2021 11:35:41 +0800 Subject: [PATCH 3/3] Use async repository method in Docs module. --- .../Docs/Documents/EFCoreDocumentRepository.cs | 14 +++++++------- .../Docs/Projects/EfCoreProjectRepository.cs | 14 +++++++------- .../Docs/Documents/MongoDocumentRepository.cs | 18 +++++++++--------- .../Docs/Projects/MongoProjectRepository.cs | 14 +++++++------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs b/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs index f096bc10d90..75420f55007 100644 --- a/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs +++ b/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs @@ -21,7 +21,7 @@ public EFCoreDocumentRepository(IDbContextProvider dbContextProv public async Task> GetListByProjectId(Guid projectId, CancellationToken cancellationToken = default) { - return await DbSet.Where(d => d.ProjectId == projectId).ToListAsync(cancellationToken: cancellationToken); + return await (await GetDbSetAsync()).Where(d => d.ProjectId == projectId).ToListAsync(cancellationToken: cancellationToken); } public async Task> GetAllAsync( @@ -45,7 +45,7 @@ public async Task> GetAllAsync( CancellationToken cancellationToken = default) { var query = ApplyFilterForGetAll( - DbSet, + await GetDbSetAsync(), projectId: projectId, name: name, version: version, @@ -87,7 +87,7 @@ public async Task GetAllCountAsync( CancellationToken cancellationToken = default) { var query = ApplyFilterForGetAll( - DbSet, + await GetDbSetAsync(), projectId: projectId, name: name, version: version, @@ -111,7 +111,7 @@ public async Task FindAsync(Guid projectId, string name, string langua bool includeDetails = true, CancellationToken cancellationToken = default) { - return await DbSet.IncludeDetails(includeDetails) + return await (await GetDbSetAsync()).IncludeDetails(includeDetails) .FirstOrDefaultAsync(x => x.ProjectId == projectId && x.Name == name && x.LanguageCode == languageCode && x.Version == version, @@ -127,7 +127,7 @@ await DeleteAsync(x => public async Task GetAsync(Guid id, CancellationToken cancellationToken = default) { - return await DbSet.Where(x => x.Id == id).SingleAsync(cancellationToken: cancellationToken); + return await (await GetDbSetAsync()).Where(x => x.Id == id).SingleAsync(cancellationToken: cancellationToken); } protected virtual IQueryable ApplyFilterForGetAll( @@ -148,7 +148,7 @@ protected virtual IQueryable ApplyFilterForGetAll( DateTime? lastCachedTimeMax, CancellationToken cancellationToken = default) { - return DbSet + return query .WhereIf(projectId.HasValue, d => d.ProjectId == projectId.Value) .WhereIf(name != null, @@ -179,4 +179,4 @@ protected virtual IQueryable ApplyFilterForGetAll( d => d.LastCachedTime.Date <= lastCachedTimeMax.Value.Date); } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Projects/EfCoreProjectRepository.cs b/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Projects/EfCoreProjectRepository.cs index 835172e6795..bf92a8a7950 100644 --- a/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Projects/EfCoreProjectRepository.cs +++ b/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Projects/EfCoreProjectRepository.cs @@ -20,7 +20,7 @@ public EfCoreProjectRepository(IDbContextProvider dbContextProvi public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount) { - var projects = await DbSet.OrderBy(sorting ?? "Id desc") + var projects = await (await GetDbSetAsync()).OrderBy(sorting ?? "Id desc") .PageBy(skipCount, maxResultCount) .ToListAsync(); @@ -30,8 +30,8 @@ public async Task> GetListAsync(string sorting, int maxResultCount public async Task GetByShortNameAsync(string shortName) { var normalizeShortName = NormalizeShortName(shortName); - - var project = await DbSet.FirstOrDefaultAsync(p => p.ShortName == normalizeShortName); + + var project = await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.ShortName == normalizeShortName); if (project == null) { @@ -44,13 +44,13 @@ public async Task GetByShortNameAsync(string shortName) public async Task ShortNameExistsAsync(string shortName) { var normalizeShortName = NormalizeShortName(shortName); - - return await DbSet.AnyAsync(x => x.ShortName == normalizeShortName); + + return await (await GetDbSetAsync()).AnyAsync(x => x.ShortName == normalizeShortName); } - + private string NormalizeShortName(string shortName) { return shortName.ToLower(); } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs b/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs index b3b52109867..d4b0a1c00e1 100644 --- a/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs +++ b/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs @@ -22,17 +22,17 @@ public MongoDocumentRepository(IMongoDbContextProvider dbCo public async Task> GetListByProjectId(Guid projectId, CancellationToken cancellationToken = default) { - return await GetMongoQueryable().Where(d => d.ProjectId == projectId).ToListAsync(cancellationToken); + return await (await GetMongoQueryableAsync(cancellationToken)).Where(d => d.ProjectId == projectId).ToListAsync(cancellationToken); } public async Task FindAsync(Guid projectId, string name, string languageCode, string version, bool includeDetails = true, CancellationToken cancellationToken = default) { - return await GetMongoQueryable().FirstOrDefaultAsync(x => x.ProjectId == projectId && - x.Name == name && - x.LanguageCode == languageCode && - x.Version == version, cancellationToken); + return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.ProjectId == projectId && + x.Name == name && + x.LanguageCode == languageCode && + x.Version == version, cancellationToken); } public async Task DeleteAsync(Guid projectId, string name, string languageCode, string version, @@ -66,7 +66,7 @@ public async Task> GetAllAsync( return await ApplyFilterForGetAll( - GetMongoQueryable(), + await GetMongoQueryableAsync(cancellationToken), projectId: projectId, name: name, version: version, @@ -110,7 +110,7 @@ public async Task GetAllCountAsync( return await ApplyFilterForGetAll( - GetMongoQueryable(), + await GetMongoQueryableAsync(cancellationToken), projectId: projectId, name: name, version: version, @@ -132,7 +132,7 @@ public async Task GetAllCountAsync( public async Task GetAsync(Guid id, CancellationToken cancellationToken = default) { - return await GetMongoQueryable().Where(x => x.Id == id).SingleAsync(cancellationToken); + return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.Id == id).SingleAsync(cancellationToken); } protected virtual IMongoQueryable ApplyFilterForGetAll( @@ -221,4 +221,4 @@ protected virtual IMongoQueryable ApplyFilterForGetAll( return query; } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs b/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs index f1312b9e5df..91f1af9b2ac 100644 --- a/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs +++ b/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs @@ -21,7 +21,7 @@ public MongoProjectRepository(IMongoDbContextProvider dbCon public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount) { - var projects = await GetMongoQueryable().OrderBy(sorting ?? "Id desc").As>() + var projects = await (await GetMongoQueryableAsync()).OrderBy(sorting ?? "Id desc").As>() .PageBy>(skipCount, maxResultCount) .ToListAsync(); @@ -31,8 +31,8 @@ public async Task> GetListAsync(string sorting, int maxResultCount public async Task GetByShortNameAsync(string shortName) { var normalizeShortName = NormalizeShortName(shortName); - - var project = await GetMongoQueryable().FirstOrDefaultAsync(p => p.ShortName == normalizeShortName); + + var project = await (await GetMongoQueryableAsync()).FirstOrDefaultAsync(p => p.ShortName == normalizeShortName); if (project == null) { @@ -45,13 +45,13 @@ public async Task GetByShortNameAsync(string shortName) public async Task ShortNameExistsAsync(string shortName) { var normalizeShortName = NormalizeShortName(shortName); - - return await GetMongoQueryable().AnyAsync(x => x.ShortName == normalizeShortName); + + return await (await GetMongoQueryableAsync()).AnyAsync(x => x.ShortName == normalizeShortName); } - + private string NormalizeShortName(string shortName) { return shortName.ToLower(); } } -} \ No newline at end of file +}