示例#1
0
        /// <summary>
        /// 获取指定字段值
        /// </summary>
        /// <typeparam name="T">泛类</typeparam>
        /// <param name="columnsName">列名</param>
        /// <param name="pkColumnsName">主键Id列名</param>
        /// <param name="pkValue">主键Id值</param>
        /// <returns></returns>
        public object GetColumnsValue <T>(string columnsName, string pkColumnsName, object pkValue) where T : IActiveRecord, new()
        {
            object obj = null;

            try
            {
                SubSonic.Query.Select select = null;

                //指定列
                select = new SubSonic.Query.Select(columnsName);
                //设置条件
                select.From <T>().Where(pkColumnsName).Equals(pkValue);

                //获取执行语句
                _execSql = select.ToString();

                obj = select.ExecuteScalar();
            }
            catch (Exception e)
            {
                throw new Exception("查询数据异常,执行语句" + _execSql, e);
            }

            return(obj);
        }
示例#2
0
        /// <summary>
        /// 获取指定字段值
        /// </summary>
        /// <typeparam name="T">泛类</typeparam>
        /// <param name="columnsName">列名</param>
        /// <param name="wheres">条件</param>
        /// <returns></returns>
        public object GetColumnsValue <T>(string columnsName, List <ConditionHelper.SqlqueryCondition> wheres = null, List <string> orderbys = null) where T : IActiveRecord, new()
        {
            object obj = null;

            try
            {
                SubSonic.Query.Select select = null;

                //指定列
                select = new SubSonic.Query.Select(columnsName);

                select.From <T>();

                //判断是否有条件
                if (wheres != null)
                {
                    //添加条件
                    ConditionHelper.SqlqueryCondition.AddSqlqueryCondition(select, wheres);
                }

                //判断是否添加排序
                if (orderbys != null)
                {
                    select.OrderBys = orderbys;
                }


                //获取执行语句
                _execSql = select.ToString();

                obj = select.ExecuteScalar();
            }
            catch (Exception e)
            {
                throw new Exception("查询数据异常,执行语句" + _execSql, e);
            }

            return(obj);
        }