Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215

Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215
NHibernate HQL 汇总查询示例 – 扎老铁
Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215

Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215
Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215
class="post-53146 post type-post status-publish format-standard hentry">

NHibernate HQL 汇总查询示例

using Rhythm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Bitlab.IOT
{
    public class GlobalSummary
    {
        public int DeviceCount { get; set; }
        public int SceneCount { get; set; }
        public int GroupCount { get; set; }
        public IList<ProjectSummary> ProjectSummarys { get; set; }
    }

    public class ProjectSummary
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public int DeviceCount { get; set; }
        public int SceneCount { get; set; }
        public int GroupCount { get; set; }
        public ProjectSummary(string id, string name, int deviceCount, int sceneCount, int groupCount)
        {
            this.Id = id;
            this.Name = name;
            this.DeviceCount = deviceCount;
            this.SceneCount = sceneCount;
            this.GroupCount = groupCount;
        }
    }

    public class SceneRepository : NHibernateRepositoryBase<Scene, SceneRepository>
    {
        public GlobalSummary QuerySummary()
        {
            IList<ProjectSummary> list = CreateQuery("selec new Bitlab.IOT.ProjectSummary(p.Id,p.Name,p.Devices.Count,p.Group.Count,p.Scenes.Count)  from DeviceProject p")
                   .List<ProjectSummary>();

            GlobalSummary globalSum = new GlobalSummary
            {
                DeviceCount = (int)CreateQuery("select count(*) from DeviceDef").FutureValue<long>().Value,
                SceneCount = (int)CreateQuery("select count(*) from  Scene").FutureValue<long>().Value,
                GroupCount = (int)CreateQuery("select count(*) from Device Group").FutureValue<long>().Value,
                ProjectSummarys = list,
            };

            return globalSum;
        }
    }
}

 

发表评论

电子邮件地址不会被公开。