public void AddCondition(bool notIn, string tableName, string fieldName, SqlExpBase sqlQuery)
        {
            var innerQuery = sqlQuery.SqlString;

            foreach (var name in sqlQuery.Parameters)
            {
                //var param = name.Key;
                //var innerParamKey = "Inner" + param;
                //innerQuery = Regex.Replace(innerQuery, param, innerParamKey);
                //AddParameter(innerParamKey, name.Value);
                this.AddParameter(name.Key, name.Value);
            }
            string op = notIn ? "NOT IN" : "IN";

            string key = _adapter.Field(tableName, fieldName);


            //if (_isSubQuery)
            //{
            //    key = _adapter.Field(JoinSubAliasTableName, fieldName);

            //}
            var newCondition = string.Format("{0} {2} ({1})", key, innerQuery, op);

            _conditions.Add(newCondition);
        }
        public void QuerySub(SqlExpBase sqlExp)
        {
            //var aliasTname = $"query_" + DateTime.Now.Ticks;
            JoinSubAliasTableName = sqlExp.JoinSubAliasTableName;
            //sqlExp.JoinSubAliasTableName = aliasTname;

            var subQueryStr = sqlExp.SqlString;

            var subTableString = string.Format("({0}) AS {1}", subQueryStr, sqlExp.JoinSubAliasTableName);

            _tableNames.Clear();
            _tableNames.Add(subTableString);
        }
        public void JoinSub(SqlExpBase sqlExp, string originalTableName, string joinTableName, string leftField, string rightField, JoinType joinType)
        {
            var joinTypeStr = "JOIN";

            switch (joinType)
            {
            case JoinType.InnerJoin:
                joinTypeStr = "INNER JOIN";
                break;

            case JoinType.LeftJoin:
                joinTypeStr = "LEFT JOIN";
                break;

            case JoinType.RightJoin:
                joinTypeStr = "RIGHT JOIN";
                break;

            case JoinType.LeftOuterJoin:
                joinTypeStr = "LEFT OUTER JOIN";
                break;

            case JoinType.RightOuterJoin:
                joinTypeStr = "RIGHT OUTER JOIN";
                break;

            default:
                joinTypeStr = "JOIN";
                break;
            }

            var aliasTname = $"join_" + DateTime.Now.Ticks;

            sqlExp.JoinSubAliasTableName = aliasTname;

            JoinSubAliasTableName = aliasTname;
            var subQueryStr = sqlExp.SqlString;

            var joinString = string.Format("{3} ({0}) {4} ON {1} = {4}.{2}",
                                           subQueryStr,
                                           _adapter.Field(originalTableName, leftField),
                                           _adapter.Field(rightField), joinTypeStr, aliasTname);

            _tableNames.Add(joinTableName);
            _joinExpressions.Add(joinString);
            _splitColumns.Add(rightField);
        }
        public void JoinSub(SqlExpBase sqlExp, string originalTableName, string joinTableName, string leftField, string rightField, JoinType joinType)
        {
            var joinTypeStr = GetJoinType(joinType);

            var aliasTname = $"join_" + DateTime.Now.Ticks;

            sqlExp.JoinSubAliasTableName = aliasTname;

            JoinSubAliasTableName = aliasTname;
            var subQueryStr = sqlExp.SqlString;

            var joinString = string.Format("{3} ({0}) {4} ON {1} = {4}.{2}",
                                           subQueryStr,
                                           _adapter.Field(originalTableName, leftField),
                                           _adapter.Field(rightField), joinTypeStr, aliasTname);

            _tableNames.Add(joinTableName);
            _joinExpressions.Add(joinString);
            _splitColumns.Add(rightField);
        }
Пример #5
0
        public void QueryByIsIn <T>(bool isNot, Expression <Func <T, object> > expression, SqlExpBase sqlQuery)
        {
            var fieldName = GetColumnName(expression);

            _builder.AddCondition(isNot, GetTableName <T>(), fieldName, sqlQuery);
        }