Created
April 15, 2018 17:57
-
-
Save NMZivkovic/4d408ead3d64007d8eb3b3ccacc80d88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Repository<TEntity> : IReporitory<TEntity> where TEntity : class | |
{ | |
protected readonly DbContext Context; | |
protected readonly DbSet<TEntity> Entities; | |
public Repository(DbContext context) | |
{ | |
Context = context; | |
Entities = Context.Set<TEntity>(); | |
} | |
public void Add(TEntity entity) | |
{ | |
Entities.Add(entity); | |
} | |
public void Remove(TEntity entity) | |
{ | |
Entities.Remove(entity); | |
} | |
public TEntity Get(int id) | |
{ | |
return Entities.Find(id); | |
} | |
public IEnumerable<TEntity> GetAll() | |
{ | |
return Entities.ToList(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment