Model in sessions

2

I have a GRID (table) that when selecting an item through the ID I load the entity in a session via ajax.

public static class Sessoes
    {
        public static Produto Produto
        {
            get
            {
                return (Produto)HttpContext.Current.Session["Produto"];
            }
            set
            {
                HttpContext.Current.Session["Produto"] = value;
            }
        }
    }

I wonder if it would be a bad decision to save every entity in a session? What do you think? Do you know any disadvantages in using this practice ?

    
asked by anonymous 20.08.2014 / 15:32

1 answer

2

It has several disadvantages.

In this link, for example, the author teaches you how to easily capture data from a session .

Putting your Produto inside a Session , you lose the lazy load capacity, because the assignment will cause the object to be detached from the context. Changes to it will not be mapped either.

There is more of an aggravation of using your application in a distributed, load-balanced environment (Azure environments, other than virtual machines, for example). Using this approach, your application will fail at runtime because Sessions were not well implemented for this type of environment.

Session needs to be viewed as a temporary cache per user, not as a general data storage resource, such as ViewBag or a ViewData dictionary.

    
20.08.2014 / 17:00