LOL, I still think why I didn't think that before. Thanks! Tuna Toksöz Eternal sunshine of the open source mind.
http://devlicio.us/blogs/tuna_toksoz http://tunatoksoz.com http://twitter.com/tehlike On Fri, Aug 28, 2009 at 3:41 PM, YJingLee <[email protected]> wrote: > > int64 count = (int64)session.CreateQuery("select count(*) from > Employees where EmployeeID = :fn") > .SetString("fn", employeeId.ToString()) > .UniqueResult(); > > > > On Aug 28, 7:54 pm, İlgiz Seber <[email protected]> wrote: > > Hi, > > > > I found a trick about casting Count() to int result on this link: > http://nhforge.org/doc/nh/en/index.html#queryhql-tipstricks > > > > Then i wrote a HQL like this: > > > > public int HQL_GetCustomerCount(int employeeId) > > { > > int count = (int)session.CreateQuery("select count(*) from > > Employees where EmployeeID = :fn") > > .SetString("fn", employeeId.ToString()) > > .UniqueResult(); > > > > return count; > > } > > > > And also i wrote a test fot it too: > > > > [Test] > > public void HQL_CanGetCustomerCount() > > { > > int count = dataProvider.HQL_GetCustomerCount(1); > > > > Assert.AreEqual(1, count); > > } > > > > Then i run my test expecting to cast count() result to int according > > to the trick, i got this exception: > > > > "NHibernateDataProviderTest.HQL_CanGetCustomerCount : Failed > > > > NHibernate: select count(*) as col_0_0_ from Employees employees0_ > > where employees0_.employee...@p0;@p0 = '1' > > > > System.InvalidCastException: Specified cast is not valid." > > > > Is it a bug or am i making a terrible mistake? > > > > NOTE: I am using NHibernate 2.1.0.4000 version. And working on > > Northwind db. > > > > Thanks to everyone. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
