You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/Infrastructure/Data/EfRepository.cs

51 lines
1.1 KiB

using System;
using System.Linq;
using Infrastructure.Domain;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Data
{
public class EfRepository<T> : IRepository<T> where T : BaseEntity
{
private readonly DbContext _dbContext;
public EfRepository(DbContext dbContext)
{
_dbContext = dbContext;
}
public IQueryable<T> Table()
{
return this._dbContext.Set<T>();
}
public IQueryable<T> ReadOnlyTable()
{
return this._dbContext.Set<T>().AsNoTracking();
}
public T FindBy(Guid id)
{
return this._dbContext.Set<T>().Find(id);
}
public void Add(T entity)
{
this._dbContext.Set<T>().Add(entity);
}
public void Update(T entity)
{
}
public void Delete(T entity)
{
this._dbContext.Set<T>().Remove(entity);
}
public int SaveChanges()
{
return this._dbContext.SaveChanges();
}
}
}