8
votes

Does NHibernate always generate update for all columns?

public class Person
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual string Address { get; set; }
}

Person p = Session.Load(1);
p.Name = "New Name";

Session.Flush();//Update for all columns, but I change only Name

Is it normal behavior for NHibernate or my mistake? I use Fluent NHibernate and AutoMapping.

2
Andy, if some of your other questions have known a solution from other's answer, please accept them so that it may help others who shall have the same question as yours.Will Marcouiller

2 Answers

11
votes

That is the default behavior, but you can make NH update modified columns only by adding dynamic-update="true" to your <class> mapping.

-2
votes

NHibernate always updates all mapped columns. This should be no trouble if the other columns didn't change, since on update the data has been previously pumped from the underlying datastore, so basically, it only reset the column values to their own orginal values. No problem about it.

If you want to override this behaviour, you need to implement the IInterceptor interface.