コード例 #1
0
        public TField GetField <TField>(ParamQuery param)
        {
            var result  = default(TField);
            var command = GetPreparedDbCommand(BuilderParse(param).Data);

            return(command == null ? result : command.QuerySingle <TField>());
        }
コード例 #2
0
        public ParamQuery ToParamQuery()
        {
            var pQuery         = new ParamQuery();
            var settings       = XElement.Parse(settingXml);
            var defaultOrderBy = getXmlElementAttr(settings, "defaultOrderBy");

            pQuery.Select(getXmlElementValue(settings, "select"));

            //获取分页及排序信息
            var page    = parseInt(request["page"], 1);
            var rows    = parseInt(request["rows"]);
            var orderby = string.Join(" ", GetFieldName(this["sort"], true), this["order"]).Trim();

            if (string.IsNullOrEmpty(orderby))
            {
                orderby = defaultOrderBy;
            }

            var sFrom    = getXmlElementValue(settings, "from");
            var sGroupby = getXmlElementValue(settings, "groupby");

            pQuery.From(sFrom).Paging(page, rows).OrderBy(orderby).GroupBy(sGroupby);
            ParseWhere(settings, (name, value, compare, variable, extend) =>
            {
                pQuery.AndWhere(name, value, compare, extend);
            });

            return(pQuery);
        }
コード例 #3
0
        public T GetModel(ParamQuery param)
        {
            //Logger("获取实体对象", () => result = BuilderParse(param).QuerySingle());
            var result = BuilderParse(param).QuerySingle();

            return(result);
        }
コード例 #4
0
        public dynamic GetDynamic(ParamQuery param)
        {
            var result  = new ExpandoObject();
            var command = GetPreparedDbCommand(BuilderParse(param).Data);

            return(command == null ? result : command.QuerySingle <dynamic>());
        }
コード例 #5
0
        public dynamic GetDynamicListWithPaging(ParamQuery param = null)
        {
            dynamic result = new ExpandoObject();

            result.rows  = this.GetDynamicList(param);
            result.total = this.QueryRowCount(param);
            return(result);
        }
コード例 #6
0
        protected int QueryRowCount(ParamQuery param)
        {
            var data          = param.GetData();
            var sFrom         = data.From.Length == 0 ? typeof(T).Name : data.From;
            var selectBuilder = db.Select <int>("COUNT(1)")
                                .From(sFrom)
                                .Where(data.WhereSql);

            return(selectBuilder.QuerySingle());
        }
コード例 #7
0
        public List <T> GetList(ParamQuery param = null)
        {
            IDbCommand command = GetPreparedDbCommand(BuilderParse(param).Data);

            if (command == null)
            {
                return(new List <T>());
            }

            var result = command.QueryMany <T>();

            return(result);
        }
コード例 #8
0
        protected ISelectBuilder <T> BuilderParse(ParamQuery param)
        {
            if (param == null)
            {
                param = new ParamQuery();
            }

            var data          = param.GetData();
            var sFrom         = data.From.Length == 0 ? typeof(T).Name : data.From;
            var selectBuilder = db.Select <T>(string.IsNullOrEmpty(data.Select) ? (sFrom + ".*") : data.Select)
                                .From(sFrom)
                                .Where(data.WhereSql)
                                .GroupBy(data.GroupBy)
                                .Having(data.Having)
                                .OrderBy(data.OrderBy)
                                .Paging(data.PagingCurrentPage, data.PagingItemsPerPage);

            return(selectBuilder);
        }
コード例 #9
0
 public List <T> GetModelList(ParamQuery param = null)
 {
     return(BuilderParse(param).QueryMany());
 }