views:

22

answers:

1

Hi all

Say I got 3 entities: Business, Employee and Payment. A payment has a foreign key to an Employee, while the Employee has an foreign key to a business.

Now, I want to create a query which gives me all payments for a given business. I really don't have a clue about how to do this - I guess I want something like:

mySession.CreateCriteria<Payment>()
    .Add(Criterion.Expression.Eq(/* Employee_FK => Employee.Business_FK == BusinessID */);

Any help would be greatly appreciated :)

+1  A: 

First, you need to map those FKs as many-to-one relationships in your model.

Then, I'd use HQL for this query instead of Criteria:

Business aBusiness = ...
var payments = session.CreateQuery("from Payment where Employee.Business = :business")
                      .SetParameter("business", aBusiness)
                      .List<Payment>();
Diego Mijelshon
They are already mapped - Should've said that :) Thanks for the HQL though.
cwap
I was in doubt because you were referring to them as "foreign keys"
Diego Mijelshon