NHibernate会议.Flush()-无故运行Update()

本文关键字:运行 Update 会议 NHibernate Flush | 更新日期: 2023-09-27 18:19:42

全部,

当急切地加载实体及其关联路径时,调用会话。Flush(),导致在关联实体上运行Update()。

例如:

发票->项目

加载单个发票和关联项目(急切地加载项目),然后调用会话。Flush()对项目运行Update()语句。在加载和刷新任何实体之间根本没有进行任何更改。

 IStatefulSession sess = PersistentInvoiceHeader.AcquireCurrentSession();
            InvoiceHeader hdr = sess.Session.CreateCriteria<InvoiceHeader>()
                    .Add(Restrictions.Eq(InvoiceHeader.PROP_ENTITYID, 25051))
                    .SetFetchMode(InvoiceHeader.PROP_PROJECT, NHibernate.FetchMode.Eager)
                    .UniqueResult<InvoiceHeader>();
            sess.Session.Flush();

跟踪(Job_Info是与发票相关联的项目实体):

NHibernate: SELECT ... FROM InvoiceHeader this_ inner join Job_Info project2_ on this_.ProjectId=project2_.entity_id WHERE this_.entity_id = @p0;@p0 = 25051 [Type: Int32 (0)]
NHibernate: UPDATE Job_Info SET RowVersion = @p0, Created = @p1, LastUpdated = @p2, public_surveyor = @p3, guid = @p4, updated_at = @p5, status = @p6, entry_date = @p7, file_number = @p8, client_reference = @p9, contact = @p10, order_date = @p11, instructions_1 = @p12, instructions_2 = @p13, instructions_3 = @p14, instrument = @p15, quote = @p16, quote_document = @p17, pin = @p18, project_notes = @p19, due_date = @p20, due_date_fw = @p21, lock_status = @p22, plan_attached = @p23, notes_attached = @p24, type_extra = @p25, currency_code = @p26, master_job_id = @p27, manager_id = @p28, contact_id = @p29, office_id = @p30, job_type_id = @p31, client_entity_id = @p32, country_id = @p33, region_id = @p34 WHERE entity_id = @p35 AND RowVersion = @p36;

我真的很惊讶Nhibernate在一些没有改变的东西上运行Update()语句!没有一个实体是脏的,为什么会有更新?

我使用的是Nhibernate 3.3,.net 4.0,这是控制台应用程序。

NHibernate会议.Flush()-无故运行Update()

谢谢你的回答,结果是一个糟糕的映射。