Best Practice for using one OpenAccessContext with multiple forms

2 posts, 0 answers
  1. Bret
    Bret avatar
    14 posts
    Member since:
    May 2011

    Posted 29 Jun 2011 Link to this post

    I'm working on porting an app over to use OpenAccess, and I'm looking for a suggestion on what I should, or should not, do regarding using the same OpenAccessContext in multiple forms. This app has the potential for the user to open several unrelated Windows forms, and switch back and forth between them doing work. Since there is some initialization overhead involved, I was thinking about creating one instance of the OpenAccessContext and having all of these child forms use it. However, I was worried that saving data in one form would cause any updates from the other forms to get pushed out to the database as well. This would be a problem for me since records on one form may not be complete when another is saved. I'm sure I could just create a new OpenAccessContext in each form, but that just seems like it might be excessive. So, I'm looking for some guidance on what is the recommended way of using OpenAccess in a project with multiple windows forms. Mostly, what do I need to do to make sure that the CUD work on one form isn't going to interfere with incomplete work on another form.

    Thanks,

    - Bret
  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 05 Jul 2011 Link to this post

    Hello Bret,

     I guess you have some form that can be called as the 'master' form, or a form that is most commonly used in your application and open during the whole lifecycle of it. In that form and all form related to it, you could have one context. That very same context can be used in all forms that are only showing read-only data as well. Please have a look into this KB article in order to see some best practices for implementing a pattern with such a long-living context.
    http://www.telerik.com/support/kb/orm/general/best-practices-in-winforms-with-orm.aspx

    For all forms that have some business logic and CRUD operations on their own, you must create a different context instance though. Creating a new context is not an expensive operation(only the first one would be expensive as some metadata information is calculated and cached then). 

    Regards,
    Zoran
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  3. DevCraft banner
Back to Top