0

Linq-to-NHibernate 是否支持在单个查询中从多个实体中检索数据?

例如:

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()

Building的父实体在哪里Floor

4

3 回答 3

2

您将需要在 session.Linq 上使用 Expand 方法。例如(对不起,在 c# 中),

var linq = session.Linq<Floor>();
linq.Expand("Building");  //causes "Building" to be eagerly loaded.
//Then your linq query goes here...
于 2009-09-02T13:45:48.003 回答
1

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.

于 2009-11-02T16:25:11.050 回答
1

这应该是可能的,因为 NHibernate 本身就支持这一点。但是我没有使用 Linq-to-NHibernate 的经验。

您是否尝试过查询,如果是,响应是什么?

于 2009-07-31T13:44:42.397 回答