using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using _0_Framework.Domain; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; namespace _0_Framework.InfraStructure { public class RepositoryBase : IRepository where T:class { private readonly DbContext _context; public RepositoryBase(DbContext context) { _context = context; } public void AddRange(IEnumerable entities) { _context.AddRange(entities); } public void Create(T entity) { _context.Add(entity); } public async Task CreateAsync(T entity) { await _context.AddAsync(entity); } public bool ExistsIgnoreQueryFilter(Expression> expression) { return _context.Set().IgnoreQueryFilters().Any(expression); } public bool Exists(Expression> expression) { return _context.Set().Any(expression); } public T Get(TKey id) { return _context.Find(id); } public List Get() { return _context.Set().ToList(); } public async Task> GetListByIdList(List ids) { return await _context.Set().Where(e => ids.Contains(EF.Property(e, "id"))).ToListAsync(); } public void Remove(T entity) { _context.Set().Remove(entity); } public void RemoveRange(IEnumerable entities) { _context.Set().RemoveRange(entities); } public void SaveChanges() { _context.SaveChanges(); } public async Task SaveChangesAsync() { await _context.SaveChangesAsync(); } public async Task BeginTransactionAsync() { return await _context.Database.BeginTransactionAsync(); } } }