-1

Hello. I have a problem with the creation of a Hibernate Criteria object. I'm new to Hibernate.

Can someone help me with the creation of a complex Criteria object and explain how this is done? Here is the sample SQL select statement to emulate:

select * from Company join Employees on Company.IDCompany = Employees.IDCompany;

MrGomez
  • 23,788
  • 45
  • 72
Endiss
  • 699
  • 2
  • 10
  • 23

1 Answers1

1

If you user NH3 you can use QueryOver instead of ICriteria, as for me QueryOver expressions are better than ICriteria strings.

Session.QueryOver<Company>()
 .JoinQueryOver(company => company.Employees)
 .Where(...) // some restrictions
 .List<Company>();

http://nhforge.org/blogs/nhibernate/archive/2009/12/17/queryover-in-nh-3-0.aspx

Anton
  • 1,583
  • 12
  • 17
  • session.QueryOver().JoinQueryOver((Company=> Company.Employees)).Where(Company.IDCompany = Employees.IDCompany).List(); It show's me that Connot resolve symbol Employees so it wont work;/ – Endiss Mar 19 '12 at 15:34
  • "Employees" should be a class property name, for example: class Company { public virtual Employee Employees { get; set; } } – Anton Mar 19 '12 at 15:38