global using Contracts; global using Entities; global using System.Linq.Expressions; global using Entities.Models; using Microsoft.EntityFrameworkCore; namespace Repository; public abstract class RepositoryBase : IRepositoryBase where T : class { protected RepositoryContext RepositoryContext { get; set; } public RepositoryBase(RepositoryContext repositoryContext) { RepositoryContext = repositoryContext; } public IQueryable FindAll() => RepositoryContext.Set().AsNoTracking(); public IQueryable FindByCondition(Expression> expression) => RepositoryContext.Set().Where(expression).AsNoTracking(); public void Create(T entity) => RepositoryContext.Set().Add(entity); public void CreateBulk(ICollection entities) => RepositoryContext.Set().AddRange(entities); public void UpdateBulk(ICollection entities) => RepositoryContext.Set().UpdateRange(entities); public void Update(T entity) => RepositoryContext.Set().Update(entity); public void Delete(T entity) => RepositoryContext.Set().Remove(entity); public void DeleteBulk(ICollection entities) => RepositoryContext.Set().RemoveRange(entities); public void Detach(T entity) => RepositoryContext.Entry(entity).State = EntityState.Detached; public void DetachBulk(ICollection entities) { foreach (var item in entities) { RepositoryContext.Entry(item).State = EntityState.Detached; } } }