How does it work in the Session Per Request template?

We are working on a project using ASP.NET MVC4. At one of the team meetings, the idea came out of using a session to request a template.

I did a little search and found out some questions here at SO, saying - in general - that this template (if you can call it) points to the ORM framework.

Small example

//GET Controller/Test

public ActionResult Test()
{
     //open database connection

     var model = new TestViewModel 
                 {
                      Clients = _clientService.GetClients(),
                      Products = _productService.GetProducts()
                 };

     //close database connection
     return View(model);
}

No session for request:

//GET Controller/Test

public ActionResult Test()
{
     var model = new TestViewModel 
                 {
                      Clients = _clientService.GetClients(), // Open and close database connection
                      Products = _productService.GetProducts() // Open and close database connection.
                 };
     return View(model);
}

Doubt

  • To contextualize how a query session works?
  • This is a good decision?
  • What is the best way to implement it? Open a connection on the Internet?
  • Is this recommended in projects with complex queries / operations?
  • Is it possible to ask a concurrency problem in transactions?
+4
2

(-, wcf, asp.net web api) . ? , , , db.

, EF ORM Find, EF , , db. , . , . , , - . , -, , , .

, , : , , , , , , , orderitem . Single Context Per-Request, SaveChanges . EF : , . , , . Single Context Per-Request, . , Single : SaveChanges , HTTP-. , , : Single , .

, , . , Single Context Per-Request, .

+1

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


All Articles