-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepositoryBase.cs
More file actions
46 lines (40 loc) · 1.3 KB
/
Copy pathRepositoryBase.cs
File metadata and controls
46 lines (40 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Contracts;
using Microsoft.EntityFrameworkCore;
namespace Repository
{
public abstract class RepositoryBase<T> : IRepositoryBase<T> where T : class
{
private readonly RepositoryContext _repositoryContext;
public RepositoryBase(RepositoryContext repositoryContext)
{
_repositoryContext = repositoryContext;
}
public void Create(T entity)
{
_repositoryContext.Set<T>().Add(entity);
}
public void Delete(T entity)
{
_repositoryContext.Set<T>().Remove(entity);
}
public IQueryable<T> FindAll(bool trackChanges)
{
return !trackChanges ? _repositoryContext.Set<T>().AsNoTracking() : _repositoryContext.Set<T>();
}
public IQueryable<T> FindByCondition(Expression<Func<T, bool>> condition, bool trackChanges)
{
return !trackChanges ? _repositoryContext.Set<T>().Where(condition).AsNoTracking() :
_repositoryContext.Set<T>().Where(condition);
}
public void Update(T entity)
{
_repositoryContext.Set<T>().Update(entity);
}
}
}