internal static String BuildColumnName(ColumnSchema schema, String freeFormat, String tableName = null)
        {
            String result = schema.Name;

//#if Oracle
//            //Oracle 关键词冲突除了添加双引号外还需要大写冲突的名称
//            result = result.ToUpper();
//#endif
            result = String.Format(freeFormat, schema.Name);
            if (!schema.DisableColumnSpecifically && tableName != null)
            {
                result = String.Format(CommonFormat.COLUMN_FORMAT, tableName, result);
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 通过类的属性信息构造一个<see cref="ColumnSchema"/> 对象
        /// </summary>
        /// <param name="propertyInfo"></param>
        /// <returns></returns>
        private static ColumnSchema GetColumnSchema(PropertyInfo propertyInfo)
        {
            ColumnSchema schema = null;

            Object[] attrs = propertyInfo.GetCustomAttributes(_ColumnAttrType, true);
            if (attrs.Length > 0)
            {
                ColumnAttribute attr = attrs[0] as ColumnAttribute;
                schema = ConvertToColumnSchema(attr);
            }
            else
            {
                schema = DeduceColumnSchema(propertyInfo);
            }
            return(schema);
        }
예제 #3
0
        public static void UpdateConvert(DbProvider dbProvider, T obj, SQLComponent component)
        {
            StringBuilder updateColumnNames = new StringBuilder();
            Int32         length            = Table <T> .Schema.PropertyInfos.Length;

            for (Int32 i = 0; i < length; ++i)
            {
                PropertyInfo info      = Table <T> .Schema.PropertyInfos[i];
                ColumnSchema colSchema = Table <T> .Schema.GetColumnSchema(info.Name);

                if (colSchema.IsPrimaryKey)
                {
                    continue;
                }
                if (colSchema.IsJoinColumn)
                {
                    continue;
                }
                Object value = Table <T> .Schema.PropertyAccessor.GetValue(i, obj);

                if (value == null)
                {
                    continue;
                }
                String      columnName    = colSchema.Name;
                String      parameterName = dbProvider.Prefix + columnName + ParaCounter <T> .CountString;
                DbParameter dbParameter   = dbProvider.DbParameter
                                            (
                    parameterName,
                    value ?? DBNull.Value,
                    colSchema.DbType
                                            );
                updateColumnNames.Append(String.Format(dbProvider.ConflictFreeFormat, columnName));
                updateColumnNames.Append(SqlKeyWord.EQUAL);
                updateColumnNames.Append(parameterName);
                updateColumnNames.Append(SqlKeyWord.COMMA);
                component.AddParameter(dbParameter);
            }
            updateColumnNames.Remove(updateColumnNames.Length - SqlKeyWord.COMMA.Length, SqlKeyWord.COMMA.Length);
            component.AppendSQLFormat(BasicSqlFormat.UPDATE_FORMAT, Table <T> .Schema.TableName, updateColumnNames.ToString());
        }