views:

61

answers:

1

We use the Fluent nHibernate repository model in a .net MVC project that I'm working on. While running a sql profile to check for areas of improvement we noticed that some objects were getting UPDATEd without an explicit Save. Does anybody know why nHibernate would choose to update an object when I select it?

Class:

public class Request : DomainEntity
    {
        public virtual string Code { get; set; }

        public virtual string PartCode { get; set; }

        public virtual string Description { get; set; }

        public virtual int Quantity { get; set; }

        public virtual decimal Price { get; set; }

        public virtual DateTime DateRecieved { get; set; }
    }

Sample usage:

var request = _repository.Query<Request>().Where(x => x.OemCode == "TEST").FirstOrDefault();

After running this code with different Request codes our trace often finds what appears to be random Updates. Any ideas?

+2  A: 

From HNhibernate documentation:

From time to time the ISession will execute the SQL statements needed to synchronize the ADO.NET connection's state with the state of objects held in memory. This process, flush, occurs by default at the following points

  • from some invocations of Find() or Enumerable()
  • from NHibernate.ITransaction.Commit()
  • from ISession.Flush()

You can override this behavior by setting the ISession.FlushMode property.

Bryan Menard