Browse Source
Merge pull request #229 from EasyAbp/async-get-dbset
Use async methods to get DbContext, Queryable, and DbSet
pull/230/head
Super
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with
12 additions and
15 deletions
-
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.EntityFrameworkCore/EasyAbp/EShop/Products/ProductDetailHistories/ProductDetailHistoryRepository.cs
-
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.EntityFrameworkCore/EasyAbp/EShop/Products/ProductHistories/ProductHistoryRepository.cs
-
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.EntityFrameworkCore/EasyAbp/EShop/Products/ProductInventories/ProductInventoryRepository.cs
-
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.EntityFrameworkCore/EasyAbp/EShop/Products/Products/ProductViewRepository.cs
-
plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.HttpApi/EasyAbp/EShop/Plugins/Booking/GrantedStores/GrantedStoreController.cs
-
plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Installer/EasyAbp.EShop.Plugins.Booking.Installer.csproj
-
plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Web/BookingWebAutoMapperProfile.cs
-
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Application/EasyAbp/EShop/Plugins/Coupons/Coupons/CouponAppService.cs
-
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Domain/EasyAbp/EShop/Plugins/Coupons/Coupons/ICouponRepository.cs
-
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.EntityFrameworkCore/EasyAbp/EShop/Plugins/Coupons/Coupons/CouponRepository.cs
-
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.HttpApi/EasyAbp/EShop/Plugins/Coupons/CouponTemplates/CouponTemplateController.cs
-
samples/EShopSample/aspnet-core/test/EShopSample.Web.Tests/EShopSampleWebTestModule.cs
|
|
|
@ -18,7 +18,7 @@ namespace EasyAbp.EShop.Products.ProductDetailHistories |
|
|
|
|
|
|
|
public async Task<ProductDetailHistory> GetAsync(Guid productDetailId, DateTime modificationTime, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var entity = await GetQueryable() |
|
|
|
var entity = await (await GetQueryableAsync()) |
|
|
|
.Where(x => x.ModificationTime == modificationTime && x.ProductDetailId == productDetailId) |
|
|
|
.FirstOrDefaultAsync(cancellationToken); |
|
|
|
|
|
|
|
|
|
|
|
@ -18,7 +18,7 @@ namespace EasyAbp.EShop.Products.ProductHistories |
|
|
|
|
|
|
|
public async Task<ProductHistory> GetAsync(Guid productId, DateTime modificationTime, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var entity = await GetQueryable() |
|
|
|
var entity = await (await GetQueryableAsync()) |
|
|
|
.Where(x => x.ModificationTime == modificationTime && x.ProductId == productId) |
|
|
|
.FirstOrDefaultAsync(cancellationToken); |
|
|
|
|
|
|
|
|
|
|
|
@ -18,7 +18,7 @@ namespace EasyAbp.EShop.Products.ProductInventories |
|
|
|
|
|
|
|
public async Task<InventoryDataModel> GetInventoryDataAsync(Guid productSkuId, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
return await GetQueryable() |
|
|
|
return await (await GetQueryableAsync()) |
|
|
|
.Where(x => x.ProductSkuId == productSkuId) |
|
|
|
.Select(x => new InventoryDataModel |
|
|
|
{ |
|
|
|
|
|
|
|
@ -20,7 +20,7 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
|
|
|
|
public virtual async Task<IQueryable<ProductView>> GetQueryableAsync(Guid categoryId) |
|
|
|
{ |
|
|
|
return await JoinProductCategoriesAsync(DbSet, categoryId); |
|
|
|
return await JoinProductCategoriesAsync(await GetDbSetAsync(), categoryId); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<IQueryable<ProductView>> WithDetailsAsync(Guid categoryId) |
|
|
|
|
|
|
|
@ -4,7 +4,6 @@ using Volo.Abp.Application.Dtos; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
|
|
|
|
namespace EasyAbp.EShop.Plugins.Booking.GrantedStores |
|
|
|
{ |
|
|
|
|
|
|
|
@ -3,7 +3,7 @@ |
|
|
|
<Import Project="..\..\..\..\common.props" /> |
|
|
|
|
|
|
|
<PropertyGroup> |
|
|
|
<TargetFramework>net5.0</TargetFramework> |
|
|
|
<TargetFramework>net6.0</TargetFramework> |
|
|
|
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest> |
|
|
|
<RootNamespace /> |
|
|
|
</PropertyGroup> |
|
|
|
|
|
|
|
@ -1,9 +1,7 @@ |
|
|
|
using EasyAbp.EShop.Plugins.Booking.ProductAssets.Dtos; |
|
|
|
using EasyAbp.EShop.Plugins.Booking.Web.Pages.EShop.Plugins.Booking.ProductAssets.ProductAsset.ViewModels; |
|
|
|
using EasyAbp.EShop.Plugins.Booking.ProductAssets.Dtos; |
|
|
|
using EasyAbp.EShop.Plugins.Booking.Web.Pages.EShop.Plugins.Booking.ProductAssets.ProductAssetPeriod.ViewModels; |
|
|
|
using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories.Dtos; |
|
|
|
using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories.Dtos; |
|
|
|
using AutoMapper; |
|
|
|
using EasyAbp.EShop.Plugins.Booking.Web.Pages.EShop.Plugins.Booking.ProductAssetCategories.ProductAssetCategory.ViewModels; |
|
|
|
using EasyAbp.EShop.Plugins.Booking.GrantedStores.Dtos; |
|
|
|
|
|
|
|
@ -38,7 +38,7 @@ namespace EasyAbp.EShop.Plugins.Coupons.Coupons |
|
|
|
protected override async Task<IQueryable<Coupon>> CreateFilteredQueryAsync(GetCouponListInput input) |
|
|
|
{ |
|
|
|
return (input.AvailableOnly |
|
|
|
? _repository.GetAvailableCouponQueryable(Clock) |
|
|
|
? await _repository.GetAvailableCouponQueryableAsync(Clock) |
|
|
|
: await _repository.GetQueryableAsync()) |
|
|
|
.WhereIf(input.UserId.HasValue, x => x.UserId == input.UserId.Value) |
|
|
|
.WhereIf(!input.AvailableOnly && !input.IncludesUsed, x => !x.UsedTime.HasValue) |
|
|
|
|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Volo.Abp.Timing; |
|
|
|
|
|
|
|
@ -7,6 +8,6 @@ namespace EasyAbp.EShop.Plugins.Coupons.Coupons |
|
|
|
{ |
|
|
|
public interface ICouponRepository : IRepository<Coupon, Guid> |
|
|
|
{ |
|
|
|
IQueryable<Coupon> GetAvailableCouponQueryable(IClock clock); |
|
|
|
Task<IQueryable<Coupon>> GetAvailableCouponQueryableAsync(IClock clock); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -17,14 +17,14 @@ namespace EasyAbp.EShop.Plugins.Coupons.Coupons |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
public virtual IQueryable<Coupon> GetAvailableCouponQueryable(IClock clock) |
|
|
|
public virtual async Task<IQueryable<Coupon>> GetAvailableCouponQueryableAsync(IClock clock) |
|
|
|
{ |
|
|
|
var now = clock.Now; |
|
|
|
|
|
|
|
return DbSet |
|
|
|
return (await GetDbSetAsync()) |
|
|
|
.Where(x => x.ExpirationTime > now) |
|
|
|
.Join( |
|
|
|
DbContext.CouponTemplates.Where(x => !x.UsableBeginTime.HasValue || x.UsableBeginTime.Value <= now), |
|
|
|
(await GetDbContextAsync()).CouponTemplates.Where(x => !x.UsableBeginTime.HasValue || x.UsableBeginTime.Value <= now), |
|
|
|
coupon => coupon.CouponTemplateId, |
|
|
|
couponTemplate => couponTemplate.Id, |
|
|
|
(coupon, couponTemplate) => coupon |
|
|
|
|
|
|
|
@ -4,7 +4,6 @@ using Volo.Abp.Application.Dtos; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
|
|
|
|
namespace EasyAbp.EShop.Plugins.Coupons.CouponTemplates |
|
|
|
{ |
|
|
|
|
|
|
|
@ -87,7 +87,7 @@ namespace EShopSample |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
app.UseVirtualFiles(); |
|
|
|
app.UseStaticFiles(); |
|
|
|
app.UseRouting(); |
|
|
|
app.UseAuthentication(); |
|
|
|
app.UseAuthorization(); |
|
|
|
|