I'm having the error:
Exception Details: System.ObjectDisposedException: The ObjectContext instance has been disposed and can not be used anymore for operations that require a connection.
When I call:
@Html.DisplayFor(modelItem => item.Cliente.Url)
This view receives a model called boleto, which contains Customers;
I'm doing 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 BolGeral function.
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 IEnumerable<boleto> clientesFiltrados
has an include not to do LazyLoad, but why then of the error as if I were doing LazyLoad, when in the controller I make the disposed?