using CMS.Plugin.$NameSpacePath$.Domain.$EntityName$;
|
using CMS.Plugin.$NameSpacePath$.EntityFrameworkCore.Extensions;
|
using CmsQueryExtensions.Extension;
|
using Microsoft.EntityFrameworkCore;
|
using System.Linq.Dynamic.Core;
|
using System.Linq.Expressions;
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
|
using Volo.Abp.EntityFrameworkCore;
|
|
|
namespace CMS.Plugin.$NameSpacePath$.EntityFrameworkCore.Repositories;
|
|
/// <summary>
|
/// $ChinaComment$²Ö´¢ÊµÏÖ
|
/// </summary>
|
public class EfCore$EntityName$Repository : EfCoreRepository<ICMSPluginDbContext, $EntityName$, Guid>, I$EntityName$Repository
|
{
|
/// <summary>
|
/// Initializes a new instance of the <see cref="EfCore$EntityName$Repository"/> class.
|
/// </summary>
|
/// <param name="dbContextProvider">The database context provider.</param>
|
public EfCore$EntityName$Repository(IDbContextProvider<ICMSPluginDbContext> dbContextProvider)
|
: base(dbContextProvider)
|
{
|
}
|
|
/// <summary>
|
/// °´ÕÕÃû³Æ²éÕÒ$ChinaComment$
|
/// </summary>
|
/// <param name="name"></param>
|
/// <param name="cancellationToken"></param>
|
/// <returns></returns>
|
public virtual async Task<$EntityName$> FindByNameAsync(string name, CancellationToken cancellationToken = default)
|
{
|
return await (await GetDbSetAsync())
|
.IncludeDetails()
|
.Where(x => !x.IsDeleted)
|
.OrderByDescending(x=>x.$OrderBy$)
|
.FirstOrDefaultAsync(t => t.$ValidateRepeatName$ == name, GetCancellationToken(cancellationToken));
|
}
|
|
/// <summary>
|
/// ÑéÖ¤Ãû³ÆÊÇ·ñ´æÔÚ$ChinaComment$
|
/// </summary>
|
/// <param name="name">УÑéÖµ</param>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public async Task<bool> NameExistAsync(string name, Guid? id = null)
|
{
|
return await (await GetDbSetAsync()).WhereIf(id.HasValue, p => p.Id != id).Where(x => !x.IsDeleted).AnyAsync(x => x.$ValidateRepeatName$ == name);
|
}
|
|
/// <summary>
|
/// »ñÈ¡×î´óÅÅÐò$ChinaComment$
|
/// </summary>
|
/// <returns></returns>
|
public async Task<int> GetMaxSortAsync()
|
{
|
var hasAny = await (await GetQueryableAsync())
|
.Where(x => !x.IsDeleted).AnyAsync();
|
if (!hasAny)
|
{
|
return 1;
|
}
|
|
var sort = await (await GetQueryableAsync())
|
.Where(x => !x.IsDeleted).MaxAsync(x => x.Sort);
|
return sort + 1;
|
}
|
|
/// <summary>
|
/// »ñÈ¡·ÖÒ³Áбí$ChinaComment$
|
/// </summary>
|
/// <param name="whereConditions"></param>
|
/// <param name="sorting"></param>
|
/// <param name="maxResultCount"></param>
|
/// <param name="skipCount"></param>
|
/// <param name="includeDetails"></param>
|
/// <param name="cancellationToken"></param>
|
/// <returns></returns>
|
public async Task<List<$EntityName$>> GetListAsync(FunReturnResultModel<Expression<Func<$EntityName$, bool>>> whereConditions, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, bool includeDetails = false, CancellationToken cancellationToken = default)
|
{
|
return await (await GetDbSetAsync())
|
.IncludeDetails(includeDetails)
|
.WhereIf(whereConditions != null, whereConditions.data)
|
.Where(x => !x.IsDeleted)
|
.OrderByDescending(x=>x.$OrderBy$)
|
.PageBy(skipCount, maxResultCount)
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
}
|
|
/// <summary>
|
/// »ñÈ¡×ÜÊý$ChinaComment$
|
/// </summary>
|
/// <param name="whereConditions"></param>
|
/// <param name="cancellationToken"></param>
|
/// <returns></returns>
|
public async Task<long> GetCountAsync(FunReturnResultModel<Expression<Func<$EntityName$, bool>>> whereConditions, CancellationToken cancellationToken = default)
|
{
|
return await (await GetQueryableAsync())
|
.WhereIf(whereConditions != null, whereConditions.data)
|
.Where(x => !x.IsDeleted)
|
.CountAsync(cancellationToken: GetCancellationToken(cancellationToken));
|
}
|
|
|
/// <inheritdoc />
|
public override async Task<IQueryable<$EntityName$>> WithDetailsAsync()
|
{
|
return (await GetQueryableAsync())
|
.Where(x => !x.IsDeleted).IncludeDetails();
|
}
|
}
|