Reputation: 157
I'm using EF to make a Binding on a DataGrid on WPF. I'm getting ObjectDisposed Exception when I try to get a set ob objects out of the model.
The model is composed of 4 tables:
The exception occurs on this method
Public Function usuariosActivos() As List(Of equipo)
Using ctx As perfpruebaEntities = New perfpruebaEntities
Return (From e In ctx.equipo
Where (e.estado_id_est = 3)
Select e).ToList
End Using
End Function
When I declare the context without Using statement, everything works. What could it be?? I've been trying in different ways, but to no avail. Could it be related to the relationships??
Upvotes: 0
Views: 42
Reputation: 6374
It's most likely caused by lazy loading. Please try the following:
Public Function usuariosActivos() As List(Of equipo)
Using ctx As perfpruebaEntities = New perfpruebaEntities
Return (From e In ctx.equipo
.Include("depto")
.Include("estado")
.Include("perfil")
Where (e.estado_id_est = 3)
Select e).ToList
End Using
End Function
Upvotes: 1