3
I’m having the mistake:
Exception Details: System.Objectdisposedexception: The Objectcontext instance has been disposed and can no longer be used for Operations that require a Connection.
When I make the call:
@Html.DisplayFor(modelItem => item.Cliente.Url)
This view receives a model called boleto, which contains Clients;
I’m doing in the controller:
        using (var BolGeral = new BoletoGeral())
        {
            IEnumerable<boleto> clientesFiltrados = BolGeral.GerarIDCImpressaoMensal();
            return View(clientesFiltrados);
        }
//se não uso o Dispose ele funciona, pois ai ele ainda está conectado e consegue recuperar os valores.
The Function BolGeral.GerarIDCImpressaoMensal();
    public IEnumerable<boleto> GerarIDCImpressaoMensal()
    {
        var DataRef = new DateTime(DateTime.Today.Year, DateTime.Today.AddMonths(1).Month, 1);
        var IdClientesSemBoleto = (from cli in db.Clientes
                                   join bol in db.Boletos on cli.ClienteId equals bol.ClienteId
                                   where bol.DataReferencia == DataRef && cli.Status == 4 && cli.Convenio == 0
                                   select cli.ClienteId);
        var clientes = db.Boletos
            .Where(s => !IdClientesSemBoleto.Distinct().Contains(s.ClienteId))
            .Where(i => i.Cliente.Status == 4 && i.Cliente.Convenio == 0);
        //fazendo o distinct
        IEnumerable<boleto> clientesFiltrados = clientes
              .Include(i => i.Cliente) // Aqui está o include
              .GroupBy(customer => customer.ClienteId)
              .Select(group => group.FirstOrDefault()).OrderBy(o => o.Cliente.Url).ToList();
        return clientesFiltrados;
    }
See that the    IEnumerable<boleto> clientesFiltrados  has a include not to do Lazyload, but because then error as if doing Lazyload, when in the controller I disposed?