0
How to do JOIN via lambda in the generic repository. I’m following the DDD architecture model.
Example:
public class BaseRepository<T> : IRepositoryBase<T> where T : class
{
private IDbContext _context;
private readonly IDbSet<T> _dbset;
public BaseRepository()
{
var contextManager = ServiceLocator.Current.GetInstance<IContextManager>() as ContextManager;
_context = contextManager.AuditorExternoContext;
_dbset = _context.Set<T>();
}
public virtual void Add(T entity)
{
_dbset.Add(entity);
}
public virtual void Update(T entity)
{
var entry = _context.Entry(entity);
_dbset.Attach(entity);
entry.State = EntityState.Modified;
}
public virtual void Delete(T entity)
{
var entry = _context.Entry(entity);
entry.State = EntityState.Deleted;
}
public T GetById(int id)
{
return _dbset.Find(id);
}
public virtual IEnumerable<T> All()
{
return _dbset.ToList();
}
public virtual IQueryable<T> AllQueryable()
{
return _dbset.AsQueryable();
}
public virtual IEnumerable<T> Find(Expression<Func<T, bool>> predicate)
{
return _dbset.Where(predicate);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!disposing) return;
if (_context == null) return;
_context.Dispose();
_context = null;
}
How I do Join I’m in a specific class?
public class FaturamentoRepository : BaseRepository<Faturamento>, IAnotacaoRepository
{
}
As I am wearing BaseRepository
the FaturamentoRepository
?
How to put the inside faturamentoReposity
.
You cannot access _dbSet directly and do the query you need?
– Renato Dinhani