Starfield
Starfield

Reputation: 119

Linq-to-nHibernate Query with multiple entities?

Does Linq-to-NHibernate support retrieving data from multiple entities in a single query?

e.g.:

Dim query = From f In context.Session.Linq(Of Floor)() _
            Select f.Id, f.Name, f.Building.Id, f.Building.Name

Dim results = query.ToList()

Where Building is the parent entity of Floor.

Upvotes: 0

Views: 1384

Answers (3)

Perhentian
Perhentian

Reputation: 860

I've been playing with Expand. Interesting point about the Repository pattern too.

The thing that immediately hit me though was the smell of the magic string "Building" in @Simon's example. I did eventually come across this blog post from Marcin Budny.

http://marcinbudny.blogspot.com/2009/10/typed-expand-for-linq-to-nhiberante.html

Works well for me.

Upvotes: 1

Simon
Simon

Reputation: 5493

You will need to use the Expand method on session.Linq. For example (sorry, in c#),

var linq = session.Linq<Floor>();
linq.Expand("Building");  //causes "Building" to be eagerly loaded.
//Then your linq query goes here...

Upvotes: 2

Jan Jongboom
Jan Jongboom

Reputation: 27322

It should be possible, as NHibernate supports this natively. Yet I have no experience with Linq-to-NHibernate.

Have you tried the query, and if yes, what was the response?

Upvotes: 1

Related Questions