NHibernate update on single property updates all properties in sql

安稳与你 提交于 2019-12-21 03:41:58

问题


I am performing a standard update in NHibernate to a single property. However on commit of the transaction the sql update seems to set all fields I have mapped on the table even though they have not changed. Surely this can't be normal behaviour in Nhibernate? Am I doing something wrong? Thanks

using (var session = sessionFactory.OpenSession())
           {
               using (var transaction = session.BeginTransaction())
               {
                   var singleMeeting = session.Load<Meeting>(10193);
                   singleMeeting.Subject = "This is a test 2";

                   transaction.Commit();
               }
           }

回答1:


This is the normal behavior. You can try adding dynamic-update="true" to your class definition to override this behavior.




回答2:


Well. yes this is normal behaviour for NHibernate. You can use generated attribute for your properties to change the behaviour. Details on Ayende's blog.

Why is this default is because with dynamics you don't get your query plan cached. And usually you don't mind that you send few more bytes over high speed network connection between your application server and database. Unless you are saving long strings where this setting is perfectly appropriate.



来源:https://stackoverflow.com/questions/813240/nhibernate-update-on-single-property-updates-all-properties-in-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!