protected override object MetaEqual(object v)
        {
            var re = "";

            re = $"{ColumnExpress}{EqualFlag}{Convert2Express(v)}";

            var rtn = new LinqDLR2SqlWhereOperator(re, ConditionValues);

            return(rtn);
        }
示例#2
0
        /// <summary>
        /// 执行select的自定义处理
        /// </summary>
        /// <typeparam name="TLastItem"></typeparam>
        /// <param name="pretable"></param>
        public virtual void DoSelect <TLastItem>(LinqDLR2Sql <TLastItem> pretable)
        {
            if (pretable.LastOperation == LinqDLR2SQLOperation.SelectMany)
            {
                _selectmanytables.AddRange(pretable._selectmanytables);
                _lastoperation = LinqDLR2SQLOperation.SelectMany;
                _orderby       = pretable._orderby;
            }
            else if (pretable.LastOperation == LinqDLR2SQLOperation.SelectJoin)
            {
                foreach (var item in pretable._jointables)
                {
                    _jointables.Add(item.Key, item.Value);
                }
                _lastoperation = LinqDLR2SQLOperation.SelectJoin;
                _orderby       = pretable._orderby;
            }
            else
            {
                _lastoperation = LinqDLR2SQLOperation.Select;
                _orderby       = pretable._orderby;
            }
            _lastwhere = pretable.LastWhere;
            //生成sql
            if (LastOperation == LinqDLR2SQLOperation.Select)
            {
                var sql     = "SELECT {prefix} {columns} FROM {tables} {alianname} {where} {orderby}";
                var prefix  = "";
                var columns = GetColumnsSql();

                var tables    = Table;
                var alianname = string.IsNullOrEmpty(AliasName) ? "" : $"as {AliasName}";
                var where = LastWhere == null ? "" : $"WHERE {LastWhere.Result}";
                var orderby = _orderby == "" ? "" : $"ORDER BY {_orderby}";
                sql = sql.Replace("{prefix}", prefix)
                      .Replace("{columns}", columns)
                      .Replace("{tables}", tables)
                      .Replace("{alianname}", alianname)
                      .Replace("{where}", where)
                      .Replace("{orderby}", orderby);
                if (LastWhere != null)
                {
                    foreach (var item in LastWhere.ConditionValues)
                    {
                        _conditionvalues.Add(item.Key, item.Value);
                    }
                }

                _sql = sql;
            }
            else if (LastOperation == LinqDLR2SQLOperation.SelectMany)
            {
                var sql     = "SELECT {prefix} {columns} FROM {tables} {where} {orderby}";
                var prefix  = "";
                var columns = GetColumnsSql();
                var tables  = "";
                foreach (LinqDLRTable table in SelectManyTables)
                {
                    tables += $"{table.Table}{(string.IsNullOrEmpty(table.AliasName) ? "," : $" AS {table.AliasName},")}";
                }
                tables    = tables == "" ? "" : tables.Substring(0, tables.Length - 1);
                var where = LastWhere == null ? "" : $"WHERE {LastWhere.Result}";
                var orderby = _orderby == "" ? "" : $"ORDER BY {_orderby}";
                sql = sql.Replace("{prefix}", prefix)
                      .Replace("{columns}", columns)
                      .Replace("{tables}", tables)
                      .Replace("{where}", where)
                      .Replace("{orderby}", orderby);

                if (LastWhere != null)
                {
                    foreach (var item in LastWhere.ConditionValues)
                    {
                        _conditionvalues.Add(item.Key, item.Value);
                    }
                }
                _sql = sql;
            }