how use using statement with domain Context

Thread is closed for posting
4 posts, 0 answers
  1. Nelson
    Nelson avatar
    62 posts
    Member since:
    Apr 2011

    Posted 02 Dec 2011 Link to this post

    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
  2. Jan Blessenohl
    Jan Blessenohl avatar
    707 posts

    Posted 02 Dec 2011 Link to this post

    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!

  3. Manuel
    Manuel avatar
    61 posts
    Member since:
    Oct 2011

    Posted 08 Feb 2012 Link to this post

    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

            LoadOperation<ParticipantesReuniao> loadOp = contextoSGA.Load(contextoSGA.GetParticipantesReuniaosQuePodemVotarQuery(AppGlobais.Globais.reuniaoGlobal.IdProp))

    Is this correct? How I should proceed?

  4. PetarP
    PetarP avatar
    754 posts

    Posted 10 Feb 2012 Link to this post

    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.

    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top