C # .NET with Entity Framework 4 - how to handle context? best practics?

We are transitioning from classic ASP with SQL and Sprocs. Our choice fell on C # .net 4 Webforms with Entity Framework 4.

My question is how to handle the context. Example:

Calling the repository function GetProductById(), which opens a new context (using), and then we change something on the object, and we save it.

When we save it, we will not be in the same context as when extracting the object.

The above was not for us. Then we tried to send context in our application. While this worked, we really did not want to work this way if we did not have to.

We are currently using the third option, storing the current context in a global variable. We keep the context when we save it. However, we are not sure if this is a viable path in the long run, or if we hit the wall with this method.

We tried to find best practices on this topic, but could not find them. Thank and help on this topic.

+3
source share
4 answers

Modifying the model of work described in this article can help, although the examples in this article are related to the MVC application, not WebForms.

http://msdn.microsoft.com/en-us/ff714955.aspx

+4
source

Use object keys

, , ( , ) , .

( , ), .

, . , . , .

ASP? MVC,

Asp.net MVC, ASP, MVC.

+1

- . BeginRequest HTTPModule. , , EndRequest.

+1

Source: https://habr.com/ru/post/1751022/


All Articles