Remove () from Entity Framework 6 only works when re-creating the connection

0

I'm creating an application using EF6 and I came across a problem. I'm using the repository concept, and when I run a delete (context.remove (obj)) and after that I reload the list and the datagrid, I realize that delete has not yet worked. So delete is only noticed when I close and reopen the screen, I assume this happens because the connection is recreated.

The following is the code responsible for the operation:

public void SalvarTodos()
    {
        _contexto.SaveChanges();
    }

    public void Excluir(Func<TEntity, bool> predicate)
    {
        _contexto.Set<TEntity>().Where(predicate).ToList().ForEach(del => _contexto.Set<TEntity>().Remove(del));
    SalvarTodos();
    }

Can anyone help me?

EDIT:

Repository method that reloads data (returns an IQueriable for later ToList ()):

public IQueryable<TEntity> GetAll()
    {
        return _contexto.Set<TEntity>();
    }

EDIT 2:

Exclusion call code in ViewModel:

public void CarregaUsuarios()
    {
        Usuarios = new BindingList<Usuario>(_app.ObterTodos().ToList());
    }

    public bool CanDelete(object args)
    {
        return (usuarioSelected != null);
    }

    public void Delete(object args)
    {
        _app.Excluir(usuarioSelected.UsuarioId);
        CarregaUsuarios();
    }

The _app.ObterAll command noted above has the following code in the Application layer:

public IQueryable<Usuario> ObterTodos()
    {
        return _repositorio.GetAll();
    }
    
asked by anonymous 27.02.2015 / 13:26

0 answers