Page 1 of 1

LinqConnect Metro

Posted: Sat 16 Mar 2013 16:23
by floatingleaf
Hi All

I was wondering the best approach to handle the context in a windows 8 app?
I am uses a reportistory pattern for data access.

Do I

1/ Create a public static variable to the context and all data access uses that single one?

or

2/ Instantiate a connection each time and close when completed?


Ade

Re: LinqConnect Metro

Posted: Mon 18 Mar 2013 13:41
by MariiaI
We don't recommend to use static instance of the DataContext, due to the fact that this one instance will accumulate obsolete data (after the data has been received, it is cached and when working for a time with one DataContext, the data in the database may change while the data in the cache will be old).
DataContext is a lightweight object, and it is recommended to use new DataContext for each unit of work instead of keeping it for a long time.