`

how to build the Example.Create() statement: 1:n Restrictions

阅读更多
           /* too slowly
            ResourceAssign raExample = new ResourceAssign();
            raExample.TargetEffortEstimation = EffortEstimationDao.GetById(effortEstimationId, false);
            raExample.TargetFiscalYear = FiscalYearDao.GetById(fiscalYearId, false);


            //IQuery query
            ICriteria query = NHibernateSessionManager.Instance.GetSession().CreateCriteria(typeof(ResourceAssign), "ra")
           //.Add(Example.Create(raExample))
           .SetProjection(Projections.ProjectionList().Add(Projections.Sum("Month10"))
           .Add(Projections.Sum("Month11"))
           .Add(Projections.Sum("Month12"))
           .Add(Projections.Sum("Month1"))
           .Add(Projections.Sum("Month2"))
           .Add(Projections.Sum("Month3"))
           .Add(Projections.Sum("Month4"))
           .Add(Projections.Sum("Month5"))
           .Add(Projections.Sum("Month6"))
           .Add(Projections.Sum("Month7"))
           .Add(Projections.Sum("Month8"))
           .Add(Projections.Sum("Month9")));//.SetResultTransformer(CriteriaUtil.AliasToEntityMap);

            object[] os = (object[])(query.UniqueResult() ?? new float[12]);
            float[] f = new float[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            for (int j = 0; j < 12; j++)
            {
                f[j] = (float)Convert.ToDouble(os[j] ?? 0);
            }

            return f;
            */

            StringBuilder sbSQL = new StringBuilder("SELECT ");
            sbSQL.Append("SUM(MANMONTH_10) AS s1, SUM(MANMONTH_11) AS s2, ");
            sbSQL.Append("SUM(MANMONTH_12) AS s3, SUM(MANMONTH_01) AS s4, ");
            sbSQL.Append("SUM(MANMONTH_02) AS s5, SUM(MANMONTH_03) AS s6, ");
            sbSQL.Append("SUM(MANMONTH_04) AS s7, SUM(MANMONTH_05) AS s8, ");
            sbSQL.Append("SUM(MANMONTH_06) AS s9, SUM(MANMONTH_07) AS s10, ");
            sbSQL.Append("SUM(MANMONTH_08) AS s11, SUM(MANMONTH_09) AS s12");

            sbSQL.Append(" FROM RESOURCE_ASSIGN");
            sbSQL.Append(" WHERE (RESOURCE_ASSIGN.FK_FISCAL_YEAR_ID =:fyid) AND (RESOURCE_ASSIGN.FK_EFFORT_ESTIMATION_ID =:eeid)");

            IQuery sqlQuery = NHibernateSessionManager.Instance.GetSession().CreateSQLQuery(sbSQL.ToString())
             .AddScalar("s1", NHibernateUtil.Single)
             .AddScalar("s2", NHibernateUtil.Single)
             .AddScalar("s3", NHibernateUtil.Single)
             .AddScalar("s4", NHibernateUtil.Single)
             .AddScalar("s5", NHibernateUtil.Single)
             .AddScalar("s6", NHibernateUtil.Single)
             .AddScalar("s7", NHibernateUtil.Single)
             .AddScalar("s8", NHibernateUtil.Single)
             .AddScalar("s9", NHibernateUtil.Single)
             .AddScalar("s10", NHibernateUtil.Single)
             .AddScalar("s11", NHibernateUtil.Single)
             .AddScalar("s12", NHibernateUtil.Single)
             .SetInt64("fyid", fiscalYearId)
             .SetInt64("eeid", effortEstimationId);

            object[] os = (object[])(sqlQuery.UniqueResult() ?? new float[12]);

            float[] f = new float[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            for (int j = 0; j < 12; j++)
            {
                f[j] = (float)Convert.ToDouble(os[j] ?? 0);
            }

            return f;
分享到:
评论

相关推荐

    Springer.The.Developer’s.Guide.to.Debugging.2008.pdf

    4.3 Example 1: Detecting Memory Access Errors . . . . . . . 36 4.3.1 Detecting an Invalid Write Access . . . . . 36 4.3.2 Detecting Uninitialized Memory Reads . . . . 37 4.3.3 Detecting Memory Leaks ....

    Restrictions用法.pdf

    1. `Restrictions.eq`: 这个方法用于创建一个等于(equal)的限制条件,例如`eq("age", new Integer(20))`会匹配年龄等于20的学生对象。 2. `Restrictions.allEq`: 如果需要设置多个等于条件,可以使用`allEq`方法...

    Restrictions用法.docx

    例如,`Restrictions.and(restriction1, restriction2)`表示同时满足`restriction1`和`restriction2`的条件,`Restrictions.or(restriction1, restriction2)`表示满足`restriction1`或`restriction2`的条件。...

    深入浅出Hibernate学习笔记

    在Hibernate 3中,Restrictions类被引入,它提供了与Expression类似的静态方法,使得构建查询条件更加简洁,如`Restrictions.eq("name","Erica")`。 另外,Hibernate还提供了Example类,它可以根据一个对象实例来...

    samba服务器配置文件详解

    3. hosts allow:该配置项用于指定可以访问 Samba 服务器的主机、子网或网域,可以使用逗号分隔多个值,例如:hosts allow = 192.168.1., 192.168.2., 127.。 4. printcap name:该配置项用于指定打印机配置文件的...

    88E1512-A0-NNP2I000.PDF

    1.使用restrictions:在使用88E1512芯片时,需要遵守相关的使用限制,例如导出控制和使用许可。 2.安全注意:在使用该芯片时,需要注意安全问题,例如数据加密和访问控制。 3.环境影响:该芯片的使用可能会对环境...

    System Security Lecture Notes (StonyBrook CSE509)

    1. **Computational Power**: The amount of computational resources available to an attacker. High computational power can enable more sophisticated attacks. 2. **Bandwidth**: While bandwidth is ...

    DEAP2.1软件

    HOW TO RUN THE PROGRAM To practice running DEAP double-click on the DEAP.EXE file name. The program will then ask for an instruction file name. Type in eg1-ins.txt (and hit the RETURN key). DEAP ...

    Sql for mysql

    CHAPTER 1 Introduction to MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2 Database, ...

    SINAMICS-DCM-Firmware-V1-5-SP1

    6. `RESTRICTIONS.PDF`:可能包含关于固件升级的限制和注意事项,用户在升级前应仔细阅读。 7. `DESCR.ONF`:另一个描述文件,可能包含与`DESCR.INF`类似的信息,但格式不同。 8. `PT_ARM7.002`:这可能是指固件针对...

    SSL How to Guide

    check_client_TLS_cert_fingerprint hash:sha1:01:23:45:67:89:AB:CD:EF:01:23:45:67:89:AB:CD:EF:01:23:45:67, ... ``` 这里的指纹需要替换为实际的指纹值。每个指纹后面都应该跟一个逗号分隔开,最后一个指纹...

    微软内部资料-SQL性能优化5

    If you build a clustered index without specifying the unique keyword, SQL Server forces uniqueness by adding a uniqueifier to the rows when necessary. This uniqueifier is a 4-byte value added as an ...

    8-07-14_MegaCLI for linux_windows

    LSIP200232870 (DFCT) Add a Gen2 to Gen3 toggle function and a check for the PCI speed to MegaSCU/CLI [ PR : LSIP200231423 ] LSIP200232927 (DFCT) Port PR 198414 to MR5.4 (Headless Boot) ...

    spring-boot-reference.pdf

    24.6.1. Loading YAML 24.6.2. Exposing YAML as Properties in the Spring Environment 24.6.3. Multi-profile YAML Documents 24.6.4. YAML Shortcomings 24.7. Type-safe Configuration Properties 24.7.1. Third...

    smoke dx10 Copyright 2007 NVIDIA Corporation

    Developer acknowledges that certain of the Materials provided in Object Code version may contain third party components that may be subject to restrictions, and expressly agrees not to attempt to ...

    JavaScript APIs HTML5

    This is particularly useful when communicating between different origins due to the same-origin policy restrictions. Methods used for messaging include: - `window.postMessage()`: Sends a message to ...

    criterion简介

    此外,Criterion 还提供了许多有用的查询限制方法,例如Restrictions.gt()、Restrictions.lt()、Restrictions.between() 等,开发者可以根据需要选择合适的方法来实现复杂的查询条件。 在实际应用中,Criterion ...

    Linux 常用网络命令

    Welcome to the example.com! ``` #### 三、其他网络命令 除了FTP和Telnet外,还有一些常用的网络命令可以帮助我们更好地管理和监控Linux系统的网络状态: **netstat**:用于显示网络连接、路由表信息、接口统计...

Global site tag (gtag.js) - Google Analytics