Reputation: 5359
I'm trying to update a single column in the table. No UPDATE issued whatsoever (checked using SQL Profiler). No errors.
dynamic-update="true"
. <property name="Deleted" />
). public virtual bool Deleted { get;set;}
).NH 3.3.0, .NET 4, x64.
using (var transaction = this._session.BeginTransaction())
{
try
{
var order = this.session.Load<Order>(id);
order.Deleted = true;
this._session.Update(order);
transaction.Commit();
}
catch (Exception)
{
transaction.Rollback();
throw;
}
}
Upvotes: 2
Views: 1906
Reputation: 52745
Based on the comments, what you are trying to do is create a proxy without getting the current state from the DB (using session.Load
), then issue a dynamic update.
This will not work. NHibernate does not record individual changes to properties; instead, it:
dynamic-update
, it will only contain the modified properties.If you use session.Load
, as soon as you access the Deleted
property, NH will load the record from the database. Whether you use session.Load
or session.Get
, session.Update
on an already tracked entity is a no-op.
Alternatively, if you already have the state for all the order properties, you can update without loading:
var order = GetTheOrderFromMemory();
order.Deleted = true;
session.Update(order);
transaction.Commit();
This will not respect dynamic-update
, as NH doesn't have a snapshot to compare with...
...which is why HQL is the only way to do a one-shot update of an individual property.
Upvotes: 4