Nhibernate HQL 匿名类(严格说是map的使用以及构造函数的使用
Posted 听哥哥的话
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nhibernate HQL 匿名类(严格说是map的使用以及构造函数的使用相关的知识,希望对你有一定的参考价值。
1.map的使用 var hql=string.Format(@"select new map( tc.LimitIndexType as LimitIndexType, tc.LimitScope as LimitScope, tb.Id as Id ) from BasLimitConfig tb,BasProductGroup ta ,BasLimitType tc where tb.LimitDim1Id =ta.Id and tb.LimitDim2Id = tc.Id "); //这个是我框架的封装其实就是session.CreateQuery var list2 = Dao.FindList<object>(info); foreach (System.Collections.Hashtable entityObj in list2) { var oField = entityObj.GetEnumerator(); while (oField.MoveNext()) { string keyName = oField.Key.ToString(); object keyValue = oField.Value; } } 2.构造函数的使用 var hql= string.Format(@"select new BasLimitConfig(tc.LimitIndexType,tc.LimitScope,tb) from BasLimitConfig tb,BasProductGroup ta ,BasLimitType tc where tb.LimitDim1Id =ta.Id and tb.LimitDim2Id = tc.Id "); 实体的构造函数如下(非缺省) public BasLimitConfig(int limitIndexType,int limitScore,BasLimitConfig b) { LimitIndexType = limitIndexType; LimitScope = limitScore; LimitConditionId = b.LimitConditionId; LimitTypeId = b.LimitTypeId; LimitTypeName = b.LimitTypeName; LimitDim1Id = b.LimitDim1Id; LimitDim1Value = b.LimitDim1Value; LimitDim2Id = b.LimitDim2Id; LimitDim2Value = b.LimitDim2Value; LowerLimitValue = b.LowerLimitValue; YellowLimitValue = b.YellowLimitValue; RedLimitValue = b.RedLimitValue; UpperLimitValue = b.UpperLimitValue; TotalAmount = b.TotalAmount; ActualIsAmount = b.ActualIsAmount; PartIsAmount = b.PartIsAmount; LimitBundleName = b.LimitBundleName; Type = b.Type; ProType = b.ProType; BusiType = b.BusiType; LimitType = b.LimitType; LimitObjectType = b.LimitObjectType; Limit1FullLevel = b.Limit1FullLevel; Limit2FullLevel = b.Limit2FullLevel; QuotaUsage = b.QuotaUsage; } //框架的封装内部调用 session.CreateQuery var quotaList = Holworth.Utility.HraUtility.ListToT<BasLimitConfig>(Dao.FindList(treeInfo));
以上是关于Nhibernate HQL 匿名类(严格说是map的使用以及构造函数的使用的主要内容,如果未能解决你的问题,请参考以下文章
NHibernate HQL 生成器支持 SQL Server 2016 时态表
NHibernate HQL Generator支持SQL Server 2016时态表
如何在 Hql 中执行 ThenFetch 以及如何分解 nhibernate linq 中的许多连接?