3

I have the following situation in my code and am not able to solve it. Situation -

var grpA = Session.QueryOver(() => _employeeGroupRelation));
var grpB = Session.QueryOver(() => _employeeGroup));

// var grpC should join grpA and grpB on _employeeGroupRelation.groupID = _employeeGroup.ID 

Question - Is there some way to join grpA and grpB using QueryOver syntax? Is it possible to do this without using the List() on grpA or grpB, because each of them will hold close to 10,000 records and I don't want to dump them into memory. Is this the right use of QueryOver? Are there cleaner ways of achieving what I'm trying to solve?

It maybe a basic doubt, but I'm a newbie to NHib and QueryOver.

Edit -

select * from employeeGroup a
inner join employeeGroupRelation b on a.ID = b.ID 

This is what I'm trying to do in SQL.

1
  • It may be more beneficial for you to ask what you are trying to achieve in SQL. I'm not sure what you are trying to do by the above. Commented Mar 27, 2012 at 20:15

1 Answer 1

10

The easiest way to do it:

session.QueryOver<EmployeeGroup>()
   .JoinQueryOver(employeeGroup => employeeGroup.EmployeeGroupRelation)
   .Take(1000) // The same as top in SQL, if you don't want load all of entities
   .TransformUsing(Transformers.DistinctRootEntity)
   .List();

"JoinQueryOver" gets "EmployeeGroup" and related "EmployeeGroupRelation" as proxy (depends from mapping) for LazyLoad

If you don't want to use LazyLoad, you can do this:

session.QueryOver<EmployeeGroup>()
   .Fetch(employeeGroup => employeeGroup.EmployeeGroupRelation).Eager
   .Take(1000) // The same as top in SQL, if you don't want load all of entities
   .TransformUsing(Transformers.DistinctRootEntity)
   .List();

"Fetch" gets "EmployeeGroup" and related "EmployeeGroupRelation" (not proxy)

Sign up to request clarification or add additional context in comments.

1 Comment

What is employeeGroup?? You have not created the alias and this will fail

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.