Beispiel #1
0
        /// <summary>
        /// 根据Keys返回字符串: param=:param,param1=:param1....
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public static string GetSQLPartialUpdate <T>(IEnumerable keys)
        {
            var mapping = MappingInfo.GetMappingInfo <T>();

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("UPDATE {0} SET ", mapping.Table);
            foreach (string key in keys)
            {
                string col = null;
                if (mapping == null)
                {
                    mapping.AllProperties.TryGetValue(key, out col);
                }
                if (col == null)
                {
                    col = key;
                }

                sb.Append(col);
                sb.Append("=");
                sb.Append(StatementParser.PREFIX);
                sb.Append(key);
                sb.Append(",");
            }
            sb.Remove(sb.Length - 1, 1);
            //sb.AppendFormat(" FROM {0} t0 ", mapping.Table); ORACLE NOT SUPPORT UPDATE/FROM
            return(sb.ToString());
        }
Beispiel #2
0
        public static string GetSqlStatementByType(Type type, String crudType, string extTableName = null)
        {
            String key = type.Name + "." + crudType;

            if (!StatementParser.StatementCache.ContainsKey(key))
            {
                string sql = StatementParser.GetMappedStaticSql(key);
                if (sql.Equals(key))
                {
                    switch (crudType)
                    {
                    case "Update":
                        sql = MappingInfo.GetMappingInfo(type, extTableName).Update;
                        break;

                    case "Insert":
                        sql = MappingInfo.GetMappingInfo(type, extTableName).Insert;
                        break;

                    case "Delete":
                        sql = MappingInfo.GetMappingInfo(type).Delete;
                        break;

                    default:
                        throw new Exception("GetSqlStatementByType found Unknow CRUD key: " + key);
                    }
                }
                StatementParser.StatementCache.Insert(key, sql);
            }
            return((string)StatementParser.StatementCache.Get(key));
        }
Beispiel #3
0
        /// <summary>
        /// 属性转列名
        /// </summary>
        protected string TryGetMappingColumn(string propertyName, bool isAddMark = true)
        {
            Type   t = this.GetMappingType();
            string col;

            if (MappingInfo.GetMappingInfo(t).AllProperties.TryGetValue(propertyName, out col))
            {
                return(isAddMark?string.Format("`{0}`", col):col);
            }

            return(isAddMark?string.Format("`{0}`", propertyName): propertyName);
        }
Beispiel #4
0
        public override string ToString()
        {
            System.Text.StringBuilder sb = new StringBuilder();
            sb.Append("\tTotalCount:");
            sb.Append(this.totalCount);
            sb.Append(Environment.NewLine);

            if (this.NamedQuery == null && this.CustomSQL == null && this.QueryObject == null)
            {
                Type t = this.GetMappingType();
                this.QueryObject = MappingInfo.GetMappingInfo(t).Table;
            }
            sb.Append(this.NamedQuery ?? (this.ToSQLString() + this.ToOrderBy()));
            IEnumerator <KeyValuePair <string, object> > enumer = this.Parameters.GetEnumerator();

            while (enumer.MoveNext())//输出参数值
            {
                sb.Append(Environment.NewLine).Append("\t").Append(StatementParser.PREFIX)
                .Append(enumer.Current.Key).Append("=").Append(enumer.Current.Value);
            }

            return(sb.ToString());
        }