This is a migrated thread and some comments may be shown as answers.

how use using statement with domain Context

3 Answers 143 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nelson
Top achievements
Rank 1
Nelson asked on 02 Dec 2011, 12:05 PM
Hi there,

I've in my silverlight application a lot of memory leaks due telerik object. One thing that I can try is using my domainContext with using statement clause, like this:

           using (SGADomainContext contexto = new SGADomainContext())
            {
                LoadOperation<Entidades> loadOp = contexto.Load(contexto.GetEntidadesPorLoginQuery(loginUtilizador, passEncriptada,     false), LoadBehavior.RefreshCurrent, LoginLoadedCallback, true);    
            }

However I can´t use, VS give me this error: type used in a using statement must be implicitly convertible to 'System.IDisposable'.

Any idea how solve this?

Thanks in advance,

Nelson Silva

3 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 02 Dec 2011, 02:53 PM
Hello Nelson,
I guess your SGADomainContext does not derive from OpenAccessContext but wraps it. To clean up the OpenAccessContext you should implement IDisposable on your SGADomainContext  class and Dispose the wrapped OpenAccessContext.

All the best,
Jan Blessenohl
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Manuel
Top achievements
Rank 1
answered on 08 Feb 2012, 01:17 PM
Hi Jan,

When I said SGADomainContext I refer to the domainContext class, that derive from OpenAccessDomainService

public partial class SGADomainContext : OpenAccessDomainService<ModeloSGA>
{
}

Is this contexto that I use to load data from database. But I read in some examples, that is possible do something like

using (SGADOMAINCONTEXT contexto = new SGADOMAINCONTEXT() )
{
        LoadOperation<ParticipantesReuniao> loadOp = contextoSGA.Load(contextoSGA.GetParticipantesReuniaosQuePodemVotarQuery(AppGlobais.Globais.reuniaoGlobal.IdProp))
}

Is this correct? How I should proceed?

Thanks
0
PetarP
Telerik team
answered on 10 Feb 2012, 03:52 PM
Hello Manuel,

Since the loading of data is not a synchronous operation disposing the context like that might lead to some problems. I would suggest that you subscribe to the completed even of the load operation and dispose the context there only after the read operation has finished.

Regards,
Petar
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Development (API, general questions)
Asked by
Nelson
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Manuel
Top achievements
Rank 1
PetarP
Telerik team
Share this question
or