I am new to Nhibernate and I am trying to fully understand why HQL is used if Nhibernate already gives you objects that represent your DB.
I would just like to know if using HQL is faster than using the objects that you get from Nhibernate?
For example:
Is this HQL query (exscuse any syntax errors remember I am new)
Code:
session.CreateQuery("select cout(*) from Foo as foo where foo.Bar as fooBar where fooBar.id= 1 and Bar.something = 'chicken'");
Faster than this
Code:
Foo myFoo = (Foo)session.Load(typeof(Foo),1);
foreach(Bar myBar in myFoo.Bar)
{
if(myBar.something == "chicken")
{
counter++;
}
}
I understand that for this example using HQL would make more sense because its a lot less work. But my question is which is faster and more efficient? I would also like to know where does the HQL query take place? Is the work done on the DB server or is it done one the application machine?