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.
53 lines
1.3 KiB
53 lines
1.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace PEIS.Repositories
|
|
{
|
|
public class Repository<TEntity> :IRepository<TEntity> where TEntity:class
|
|
{
|
|
public readonly DbContext Context;
|
|
|
|
public Repository(DbContext context)
|
|
{
|
|
Context = context;
|
|
}
|
|
|
|
public TEntity Get(int id)
|
|
{
|
|
return Context.Set<TEntity>().Find(id);
|
|
}
|
|
|
|
public IEnumerable<TEntity> GetAll()
|
|
{
|
|
return Context.Set<TEntity>().ToList();
|
|
}
|
|
|
|
public IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> predicate)
|
|
{
|
|
return Context.Set<TEntity>().Where(predicate);
|
|
}
|
|
|
|
public void Add(TEntity entity)
|
|
{
|
|
Context.Set<TEntity>().Add(entity);
|
|
}
|
|
|
|
public void AddRange(IEnumerable<TEntity> entities)
|
|
{
|
|
Context.Set<TEntity>().AddRange(entities);
|
|
}
|
|
|
|
public void Remove(TEntity entity)
|
|
{
|
|
Context.Set<TEntity>().Remove(entity);
|
|
}
|
|
|
|
public void RemoveRange(IEnumerable<TEntity> entities)
|
|
{
|
|
Context.Set<TEntity>().RemoveRange(entities);
|
|
}
|
|
}
|
|
}
|
|
|