2
I have the following code snippet:
var nivel = 1;
List<meuObjeto> meusObjetos = new List<meuObjeto>();
using(var objectContext = ((IObjectContextAdapter)db).ObjectContext)
{
var cmd = string.Format(@"SELECT *
FROM meuObjeto
WHERE meuObjetoNivel = {0}", nivel);
meusObjetos.AddRange(objectContext.ExecuteStoreQuery<meuObjeto>(cmd).ToList());
}
The problem is that when trying to access any object from the list meusObjetos outside the context of using I receive Exception with the following description:
Objectdisposedexception
The Objectcontext instance has been dropped and can no longer be used for operations requiring a connection.
I can even accept that for ObjectContext implement the interface IDisposable leaving the context of using his data is no longer accessible, but how then can I make my objects 'independent" of ObjectContext and remain existing even after the Dispose() thus maintaining the using?
The problem is that you are adding a reference to the data in
objectContextand not making a copy of them.– Jéf Bueno
exact, but there is some way to make a practical copy of them?
– Jedaias Rodrigues
Cool that, huh? ) I find it unlikely to help but tried to play in a variable, even if it is just to test, and only then play in the list? Do the test by trying to access the variable outside the
using. If you can, then try the list.– Maniero
@bigown couldn’t quite understand what you meant...
– Jedaias Rodrigues