Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fluent NHibernate HQL将多个类类型分配给多个表选择查询_Nhibernate_Select_Hql_Fluent - Fatal编程技术网

Fluent NHibernate HQL将多个类类型分配给多个表选择查询

Fluent NHibernate HQL将多个类类型分配给多个表选择查询,nhibernate,select,hql,fluent,Nhibernate,Select,Hql,Fluent,我知道如何将类类型分配给从单个表检索的数据,如下所示: HQL查询: select s from Employee e join e.Store s where s.Id = 1 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

我知道如何将类类型分配给从单个表检索的数据,如下所示:

HQL查询:

select s from Employee e join e.Store s where s.Id = 1
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();//使用List()而不是List())
for(int i=0;i
您需要指定一个变压器。一个选项是指定EntityMap转换器

session.CreateQuery.SetTransformer(Transformers.AliasToEntityMap)
这将根据您的查询返回包含名称-值对的词典列表。或者,您可以创建映射到查询的POCO对象

public class MyProjection
{
   public string SName { get; set; }
   public string PName { get; set; }
   public float Price { get; set; }
   public string Aisle { get; set; }
   public string Shelf { get; set; }
}
然后指定一个不同的转换器

session.CreateQuery.SetTransformer(Transformers.AliasToBean<MyProjection>())
      .List<MyProjection>();

您需要指定一个转换器。一个选项是指定EntityMap转换器

session.CreateQuery.SetTransformer(Transformers.AliasToEntityMap)
这将根据您的查询返回包含名称-值对的词典列表。或者,您可以创建映射到查询的POCO对象

public class MyProjection
{
   public string SName { get; set; }
   public string PName { get; set; }
   public float Price { get; set; }
   public string Aisle { get; set; }
   public string Shelf { get; set; }
}
然后指定一个不同的转换器

session.CreateQuery.SetTransformer(Transformers.AliasToBean<MyProjection>())
      .List<MyProjection>();