Esempio n. 1
0
        /// <summary>
        /// 获取父节点列表Sql语句
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="fieldName">字段名</param>
        /// <param name="fieldValue">字段值</param>
        /// <param name="order">排序</param>
        /// <param name="idOnly">是否只需要主键</param>
        /// <param name="conditionBuilder">条件生成器</param>
        /// <returns></returns>
        public string GetParentsByCode(string tableName, string fieldName, string fieldValue, string order, bool idOnly = false,
                                       Action <IConditionBuilder> conditionBuilder = null)
        {
            StringBuilder sb = new StringBuilder();

            if (idOnly)
            {
                sb.AppendFormat("select {0} ", SqlBusinessLogicOptions.FieldId);
            }
            else
            {
                sb.Append("select * ");
            }
            sb.AppendFormat(" from {0} ", tableName);

            ConditionBuilder builder = new ConditionBuilder();

            builder.AppendRaw("(LEFT({0}, LEN({1})) = {1}) ", builder.AddParameter(fieldName, fieldValue), fieldName);
            conditionBuilder?.Invoke(builder);

            sb.Append(builder.ToString());

            _currentParamDict = builder.GetParamDict();

            sb.AppendFormat(" order by {0}", order);

            return(sb.ToString());
        }
Esempio n. 2
0
        public void Test_CustomParam()
        {
            ConditionBuilder builder = new ConditionBuilder();

            builder.AppendRaw("(LEFT({0}, LEN({1})) = {1}",
                              builder.AddParameter("ParentID", "BB2A1B4A-5E9E-33D5-697B-39E37974ACC4"), "ParentID")
            .Equal("IsDeleted", 1).Equal("Status", 1);
            var result = builder.ToString();
            var param  = builder.GetParamDict().ToJson();

            Console.WriteLine(result);
            Console.WriteLine(param);
        }