-
Notifications
You must be signed in to change notification settings - Fork 0
/
Repository.cs
41 lines (39 loc) · 1.01 KB
/
Repository.cs
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 System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkConcpets
{
class Repository<T> : IRespository<T> where T : class
{
EmployeeSystemEntities dbcontext;
DbSet<T> dbSet;// Dbset is the collection of all entities
public Repository(EmployeeSystemEntities context)
{
dbcontext = context;
dbSet = context.Set<T>();
}
public void Create(T entity)
{
dbSet.Add(entity);
}
public void Delete(T entity)
{
dbSet.Remove(entity);
}
public List<T> GetAll()
{
return dbSet.ToList();
}
public T getById(int id)
{
return dbSet.Find(id);
}
public void Update(T entity)
{
dbcontext.Entry<T>(entity).State = EntityState.Modified;
}
}
}