Initial commit carried over from private repo. This is V2.
This commit is contained in:
26
code/MessengerApi.Db/Repositories/Repository.cs
Normal file
26
code/MessengerApi.Db/Repositories/Repository.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using MessengerApi.Db.Contracts.Entities;
|
||||
using MessengerApi.Db.Contracts.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MessengerApi.Db.Repositories
|
||||
{
|
||||
public abstract class Repository<T> : IRepository<T> where T : class, IEntity<T>
|
||||
{
|
||||
protected readonly DbSet<T> db;
|
||||
|
||||
public Repository(DbSet<T> db)
|
||||
{
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
public void Add(T entity)
|
||||
{
|
||||
this.db.Add(entity);
|
||||
}
|
||||
|
||||
public T GetById(Guid id)
|
||||
{
|
||||
return this.db.Single(x => x.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user