我尝试使用动态实例化将以下 NHibernate 查询转换为 IList<t> 而不是 IList。
IList<AllName> allNames =
(IList<AllName>)Session.CreateQuery(
@"select new AllName(
name.NameId, name.FirstName, origin.OriginId, origin.Description,
name.Sex, name.Description, name.SoundEx
) from Name name join name.Origin origin")
.SetFirstResult(skip)
.SetMaxResults(pageSize);
运行这个我得到以下错误: -
无法将类型为“NHibernate.Impl.QueryImpl”的对象转换为类型“System.Collections.Generic.IList`1[Domain.Model.Entities.AllName]”。
我知道我可以回来
IList results = Sesssion.CreateQuery(...
但我的服务层期望
IList<AllName>
我怎样才能做到这一点?