-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepositoryBase.cs
More file actions
41 lines (33 loc) · 1.2 KB
/
Copy pathRepositoryBase.cs
File metadata and controls
41 lines (33 loc) · 1.2 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
using Contracts;
using Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Linq.Expressions;
namespace Repository
{
public class RepositoryBase<T>: IRepositoryBase<T> where T : class
{
protected RepositoryContext RepositoryContext;
public RepositoryBase(RepositoryContext repositoryContext)
{
RepositoryContext = repositoryContext;
}
public IQueryable<T> FindAll(bool trackChanges) =>
!trackChanges ?
RepositoryContext.Set<T>()
.AsNoTracking() :
RepositoryContext.Set<T>();
public IQueryable<T> FindByCondition(Expression<Func<T, bool>> expression,
bool trackChanges) =>
!trackChanges ?
RepositoryContext.Set<T>()
.Where(expression)
.AsNoTracking() :
RepositoryContext.Set<T>()
.Where(expression);
public void Create(T entity) => RepositoryContext.Set<T>().Add(entity);
public void Update(T entity) => RepositoryContext.Set<T>().Update(entity);
public void Delete(T entity) => RepositoryContext.Set<T>().Remove(entity);
}
}