【发布时间】:2011-04-06 13:15:22
【问题描述】:
我知道如何将类类型分配给从单个表中检索到的数据,如下所示:
HQL 查询:
select s from Employee e join e.Store s where s.Id = 1
代码:
var stores = session.CreateQuery(hql).List<Store>();
foreach (var store in stores)
{
Console.WriteLine(store.Name);
foreach (var product in store.Products)
{
Console.WriteLine(" " + product.Name);
}
}
但是我们如何将多个类类型分配给多个表连接查询呢?目前我无法指定任何类类型,因为数据来自多个表。
HQL 查询:
select distinct s.Name,p.Name,p.Price,p.Location.Aisle,p.Location.Shelf from Store s join s.Products p where s.Id = 1
代码:
var rows = session.CreateQuery(hql).List(); // Using List() instead of List<T>()
for (int i = 0; i < rows.Count; i++)
{
IList cols = (IList)rows[i];
for (int j = 0; j < cols.Count; j++)
{
Console.Write(cols[j] + " ");
}
Console.WriteLine("");
}
【问题讨论】:
标签: nhibernate select hql fluent