views:

59

answers:

1

I have a simple NHiberntate linq query:

var queryable = session.Linq<Product>().Where(p => p.Active);
Product[] products = queryable.ToArray();

The moment the ToArray() is executed the session becomes dirty (session.IsDirty() returns true). If the transaction is commited there is an UPDATE SQL query generated for each product.

Why are the products marked as dirty after a simple SQL SELECT?

In this project we are using the folowing framework/tools:

  • .Net 3.5 + WPF
  • NHibernate 2.1.2 + FluentNHibernate
  • SQlite
  • PostSharp 1.5
+3  A: 

this problem is called "Ghost"

this test will detect this kind of problems: http://fabiomaulo.blogspot.com/2008/10/how-test-your-mappings-ghostbuster.html

this is my improvement, is a little bit more verbose, and thus it will give you more information: http://jfromaniello.blogspot.com/2010/02/nhibernate-ghostbuster-version-11.html

José F. Romaniello
Thank you very much, that was it. I used a plain SQL script to intialize the data and some columns mapped to int properties where initialized to NULL. Your test passed tho, I think it's because it only tests the first entity of each type.
Catalin DICU