NHibernate: Unexpected row count: 0; expected: 1

Posted by Zafar Ullah - zafarjcp@gmail.com | 6:32 AM | , , , , | 0 comments »

here are some of my experiences when "Unexpected row count: 0; expected: 1" comes and also how can we solve them.

1. If primarykey generator has some issue e.g you in class its identity and in db its not an identity column. For those columns where your db column is not identity and its part of a requirment then "hilo" works :) for details on generator clickhere

2. Nhibernate seems to have problems when you create multiple transient entities that reference each other, and then try to save just the root entity. To avoid these problems, call
session.Save() on each transient entity after you create it, before you attach it to others else
use session.Update().

0 comments