在 Abp 的 ApplicationService 中进行复杂查询示例:
public virtual async Task<PagedResultDto<RawMaterialOutwarehouseRecordWithDetialsDto>>
GetRawMaterialOutwarehouseRecordListAsync(GetRawMaterialOutwarehouseRecodsInput input)
{
var query =
from outwarehouseRecord in (await _rawMaterialOutwarehouseRecordRepository.GetQueryableAsync())
join rawMaterial in (await _rawMaterialRepository.GetQueryableAsync())
on outwarehouseRecord.RawMaterialId equals rawMaterial.Id
join leftFinishProduct in (await _finishProductRepository.GetQueryableAsync())
on outwarehouseRecord.FinishProductId equals leftFinishProduct.Id into LeftJionFinishProduct
from finishProduct in LeftJionFinishProduct.DefaultIfEmpty() // 左连接
join leftOrder in (await _orderRepository.GetQueryableAsync())
on outwarehouseRecord.OrderId equals leftOrder.Id into LeftJionOrder
from order in LeftJionOrder.DefaultIfEmpty() // 左连接
select new
{
outwarehouseRecord,
rawMaterialSerialNumber = rawMaterial.SerialNumber,
rawMaterialName = rawMaterial.Name,
finishProductSerialNumber = finishProduct != null ? finishProduct.SerialNumber : null,
orderSerialNumber = order != null ? order.SerialNumber : null,
};
query = query
.WhereIf(
!input.Filter.IsNullOrWhiteSpace(),
x => x.rawMaterialSerialNumber.Contains(input.Filter) ||
(x.rawMaterialName != null && x.rawMaterialName.Contains(input.Filter))
)
.WhereIf(!string.IsNullOrWhiteSpace(input.RawMaterialSerialNumber), x => x.rawMaterialSerialNumber == input.RawMaterialSerialNumber)
.WhereIf(!string.IsNullOrWhiteSpace(input.RawMaterialName), x => x.rawMaterialName == input.RawMaterialName)
.WhereIf(!string.IsNullOrWhiteSpace(input.FinishProductSerialNumber), x => x.finishProductSerialNumber == input.FinishProductSerialNumber)
.WhereIf(!string.IsNullOrWhiteSpace(input.OrderSerialNumber), x => x.orderSerialNumber == input.OrderSerialNumber)
.WhereIf(input.MaxOutwarehouseTime != null, x => x.outwarehouseRecord.OutwarehouseTime <= input.MaxOutwarehouseTime)
.WhereIf(input.MinOutwarehouseTime != null, x => x.outwarehouseRecord.OutwarehouseTime >= input.MaxOutwarehouseTime)
.WhereIf(input.MaxCreationTime != null, x => x.outwarehouseRecord.CreationTime <= input.MaxCreationTime)
.WhereIf(input.MinCreationTime != null, x => x.outwarehouseRecord.CreationTime >= input.MinCreationTime)
.WhereIf(input.MaxModifitionTime != null, x => x.outwarehouseRecord.LastModificationTime <= input.MaxModifitionTime)
.WhereIf(input.MinModifitionTime != null, x => x.outwarehouseRecord.LastModificationTime >= input.MinModifitionTime);
var queryResult = await AsyncExecuter.ToListAsync(query);
var outhouseRecordDtos = queryResult.Select(x =>
{
var outwarehouseRecordDto = ObjectMapper.Map<RawMaterialOutwarehouseRecord, RawMaterialOutwarehouseRecordWithDetialsDto>(x.outwarehouseRecord);
outwarehouseRecordDto.RawMaterialSerialNumber = x.rawMaterialSerialNumber;
outwarehouseRecordDto.RawMaterialName = x.rawMaterialName;
outwarehouseRecordDto.FinishProductSerialNumber = x.finishProductSerialNumber;
outwarehouseRecordDto.OrderSerialNumber = x.orderSerialNumber;
return outwarehouseRecordDto;
}).ToList();
var totalCount = await AsyncExecuter.CountAsync(query);
return new PagedResultDto<RawMaterialOutwarehouseRecordWithDetialsDto>(
totalCount,
outhouseRecordDtos
);
}
标签:vNext,outwarehouseRecordDto,WhereIf,outwarehouseRecord,await,Abp,ApplicationServ
From: https://www.cnblogs.com/easy5weikai/p/17761919.html