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

Best Practice for using one OpenAccessContext with multiple forms

1 Answer 121 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bret
Top achievements
Rank 1
Bret asked on 29 Jun 2011, 10:29 PM
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

1 Answer, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 05 Jul 2011, 06:41 AM
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.
Tags
Getting Started
Asked by
Bret
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Share this question
or