-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepository.cs
More file actions
70 lines (59 loc) · 1.65 KB
/
Repository.cs
File metadata and controls
70 lines (59 loc) · 1.65 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using AzureDevopsStateTracker.Data.Context;
using AzureDevopsStateTracker.Entities;
using AzureDevopsStateTracker.Interfaces.Internals;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
namespace AzureDevopsStateTracker.Data
{
internal abstract class Repository<TEntity> : IRepository<TEntity> where TEntity : Entity
{
protected readonly AzureDevopsStateTrackerContext Db;
protected readonly DbSet<TEntity> DbSet;
public Repository(AzureDevopsStateTrackerContext db)
{
Db = db;
DbSet = db.Set<TEntity>();
}
public virtual void Add(TEntity entity)
{
DbSet.Add(entity);
}
public virtual void Add(IEnumerable<TEntity> entities)
{
DbSet.AddRange(entities);
}
public virtual void Update(TEntity entity)
{
DbSet.Update(entity);
}
public virtual void Update(IEnumerable<TEntity> entities)
{
DbSet.UpdateRange(entities);
}
public virtual void Delete(TEntity entity)
{
DbSet.Remove(entity);
}
public virtual TEntity GetById(string id)
{
return DbSet
.Where(x => x.Id == id)
.FirstOrDefault();
}
public bool Exist(string id)
{
return DbSet
.Any(x => x.Id == id);
}
public void SaveChanges()
{
Db.SaveChanges();
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
}
}