I'm migrating from EntityFramework 6x to the core EntityFramework, but I'm catching up a bit to implement an IDBSet interface that does not exist in EF Core. In its place, I need to use something like MyContext.Set ... but I do not know how to do this correctly. Does anyone know how to help me?
//MyBaseRepository
public class RepositoryBase<TEntity> : IRepositoryBase<TEntity> where TEntity : class
{
protected readonly SistemaComercialContext Context;
public RepositoryBase(SistemaComercialContext dbContext)
{
Context = dbContext;
}
public void Add(TEntity obj)
{
Context.Set<TEntity>().Add(obj);
}
public TEntity GetById(Guid id)
{
return Context.Set<TEntity>().Find(id);
}
public virtual IEnumerable<TEntity> GetAll()
{
return Context.Set<TEntity>().ToList();
}
public virtual IEnumerable<TEntity> GetAllReadOnly()
{
return Context.Set<TEntity>().AsNoTracking();
}
public void Update(TEntity obj)
{
var entry = Context.Entry(obj);
Context.Set<TEntity>().Attach(obj);
entry.State = EntityState.Modified;
}
public void Remove(TEntity obj)
{
Context.Set<TEntity>().Remove(obj);
}
public IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> predicate)
{
return Context.Set<TEntity>().Where(predicate);
}
public void Dispose()
{
Context.Dispose();
GC.SuppressFinalize(this);
}
}