39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using System.Linq.Expressions;
|
|
using SJZY.Track.Domain.Queries;
|
|
using SJZY.Track.Domain.SeedWork;
|
|
|
|
namespace SJZY.Track.Repository.Queries;
|
|
|
|
/// <summary>
|
|
/// basic queries
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
public class BasicQuery<T> : SimpleClient<T>, IBasicQuery<T> where T : class, IEntity, new()
|
|
{
|
|
/// <inheritdoc />
|
|
public BasicQuery()
|
|
{
|
|
Context = SqlsugarScopeBasic.GetContextSafely("default");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<TResult?> GetFirstAsync<TResult>(Expression<Func<T, bool>> whereExpression,
|
|
Expression<Func<T, TResult>> resultExpression)
|
|
{
|
|
return await Context.Queryable<T>().Where(whereExpression).Select(resultExpression).FirstAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<TResult>> GetListAsync<TResult>(Expression<Func<T, bool>> whereExpression,
|
|
Expression<Func<T, TResult>> resultExpression)
|
|
{
|
|
return await Context.Queryable<T>().Where(whereExpression).Select(resultExpression).ToListAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<TResult[]> GetArrayAsync<TResult>(Expression<Func<T, bool>> whereExpression,
|
|
Expression<Func<T, TResult>> resultExpression)
|
|
{
|
|
return await Context.Queryable<T>().Where(whereExpression).Select(resultExpression).ToArrayAsync();
|
|
}
|
|
} |