NHibernate Readonly Entities in Runtime

I would like to know if there is a way to make an instance of an object immutable at runtime. I know that I can only have readonly types, but I would like to see only type instances in runtime mode. The reason is because I want to use NH domain objects, such as a lightweight object, by changing properties, but I do not want these changes to be saved when Session.Flush () or similar is executed. There is always Session.Evict (), but this will not prevent the developer of unknown from Session.Save () for the readonly object.

+3
source share
2 answers

At runtime, huh? I am still a little puzzled by what exactly you ask, but I did something similar in the past:

foreach (var order in orders)
{
    _nhSession.SetReadOnly(order, true); //prevent database updates
}

, , , , . , NHibernate , , , #, , NULL, 0 #,

+5

, .

+1

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


All Articles