You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.8 KiB
59 lines
1.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Threading.Tasks;
|
|
using LinqToDB;
|
|
using Volo.Abp.Domain.Entities;
|
|
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp.Bases;
|
|
|
|
public abstract class Linq2DbCrudRepository<TEntity> : ILinq2DbRepository<TEntity>
|
|
where TEntity : class, IEntity
|
|
{
|
|
protected readonly TyrpDb TyrpDb;
|
|
|
|
public Linq2DbCrudRepository(TyrpDb tyrpDb)
|
|
{
|
|
TyrpDb = tyrpDb;
|
|
}
|
|
|
|
public virtual async Task InsertAsync(TEntity entity)
|
|
{
|
|
await TyrpDb.InsertAsync(entity).ConfigureAwait(false);
|
|
}
|
|
|
|
public virtual async Task UpdateAsync(TEntity entity)
|
|
{
|
|
await TyrpDb.UpdateAsync(entity).ConfigureAwait(false);
|
|
}
|
|
|
|
public virtual async Task DeleteAsync(TEntity entity)
|
|
{
|
|
await TyrpDb.DeleteAsync(entity).ConfigureAwait(false);
|
|
}
|
|
|
|
public virtual async Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> expression)
|
|
{
|
|
var parts = await GetListFromDbAsync(expression).ConfigureAwait(false);
|
|
return parts[0];
|
|
}
|
|
|
|
public virtual async Task<IEnumerable<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> expression = null)
|
|
{
|
|
var parts = await GetListFromDbAsync(expression).ConfigureAwait(false);
|
|
return parts;
|
|
}
|
|
|
|
private async Task<List<TEntity>> GetListFromDbAsync(Expression<Func<TEntity, bool>> expression)
|
|
{
|
|
var parts = await TyrpDb.GetTable<TEntity>().WhereIf(expression != null, expression).ToListAsync().ConfigureAwait(false);
|
|
return parts;
|
|
}
|
|
|
|
public virtual async Task<long> CountAsync(Expression<Func<TEntity, bool>> expression)
|
|
{
|
|
return await TyrpDb.GetTable<TEntity>().CountAsync(expression).ConfigureAwait(false);
|
|
}
|
|
}
|
|
|