38 lines
1018 B
C#
38 lines
1018 B
C#
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace NetinaShop.Repository.Repositories.Base
|
|
{
|
|
public class Repository<T> : IRepository<T> where T : class, IApiEntity
|
|
{
|
|
protected readonly ApplicationContext DbContext;
|
|
|
|
public Repository(ApplicationContext dbContext)
|
|
{
|
|
DbContext = dbContext;
|
|
Entities = DbContext.Set<T>();
|
|
DbContext.ChangeTracker.Clear();
|
|
}
|
|
|
|
public DbSet<T> Entities { get; }
|
|
|
|
public virtual IQueryable<T> Table => Entities.Where(e => !e.IsRemoved);
|
|
|
|
public virtual IQueryable<T> TableNoTracking => Table.AsNoTracking();
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
DbContext?.Dispose();
|
|
}
|
|
|
|
public IQueryable<T> ExecuteCommand(FormattableString command)
|
|
{
|
|
return DbContext.Set<T>().FromSql(command);
|
|
}
|
|
}
|
|
} |