57 lines
1.1 KiB
C#
57 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using _0_Framework_b.Domain;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace _0_Framework_b.InfraStructure
|
|
{
|
|
public class RepositoryBase<TKey, T> : IRepository<TKey, T> where T : class
|
|
{
|
|
private readonly DbContext _context;
|
|
|
|
public RepositoryBase(DbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
|
|
public void Create(T entity)
|
|
{
|
|
_context.Add(entity);
|
|
}
|
|
|
|
public bool Exists(Expression<Func<T, bool>> expression)
|
|
{
|
|
return _context.Set<T>().Any(expression);
|
|
}
|
|
|
|
public T Get(TKey id)
|
|
{
|
|
return _context.Find<T>(id);
|
|
}
|
|
|
|
public List<T> Get()
|
|
{
|
|
return _context.Set<T>().ToList();
|
|
}
|
|
public void Remove(T entity)
|
|
{
|
|
_context.Set<T>().Remove(entity);
|
|
}
|
|
|
|
public void RemoveRange(IEnumerable<T> entities)
|
|
{
|
|
_context.Set<T>().RemoveRange(entities);
|
|
}
|
|
public void SaveChanges()
|
|
{
|
|
_context.SaveChanges();
|
|
}
|
|
|
|
}
|
|
}
|