count(*) always returns 1 less than the actual value.
This looks like a bug to me unless we doing something wrong!
test:
Code:
[TestMethod]
public void CheckRowCount()
{
Repository repository = new Repository();
int rowCount = repository.GetRowCount<RecordOfAdvice>();
RecordOfAdvice r5 = new RecordOfAdvice(1);
RecordOfAdvice r4 = new RecordOfAdvice(1);
RecordOfAdvice r3 = new RecordOfAdvice(1);
RecordOfAdvice r2 = new RecordOfAdvice(1);
RecordOfAdvice r1 = new RecordOfAdvice(1);
r1.Save();
r2.Save();
r3.Save();
r4.Save();
r5.Save();
Assert.AreEqual(rowCount +5, repository.GetRowCount<RecordOfAdvice>());
}
the count code
Code:
public int GetRowCount<T>() where T: IEntity
{
string typeName = typeof(T).Name;
IList listCount = Session.Find(String.Format("select count(*) from {0}", typeName));
int count = Convert.ToInt32(listCount[0].ToString());
return count;
}