NHibernate session.Flush() - 无缘无故地运行Update()

时间:2014-08-28 16:52:03

标签: c# .net nhibernate

所有

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

例如:

发票 - >项目

加载单个发票和关联的项目(急切地加载项目),然后调用session.Flush()在项目上运行Update()语句。负载和Flush之间没有任何变化到任何实体。

 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,这是控制台应用。

1 个答案:

答案 0 :(得分:0)

感谢您的回答, - 结果证明这是一个不好的映射。