public string ToString(ClassMetadata classMetadata) { var orderStr = new StringBuilder(); var i = 0; foreach (var subOrder in subOrders) { if (i > 0) { orderStr.Append(","); } orderStr.Append(subOrder.ToString(classMetadata)); i++; } return orderStr.Length > 0 ? string.Format(" ORDER BY {0}" , orderStr) : ""; }
public string ToString(ClassMetadata classMetadata) { var columnInfo = classMetadata.ColumnInfos.Find(p => p.PropertyName == this.PropertyName); return columnInfo != null ? new StringBuilder().Append(columnInfo.Name).Append(" ").Append(IsAscending ? "ASC" : "DESC").ToString() : string.Empty; }
private static ClassMetadata CreatePersistentClass(System.Type type) { ClassMetadata result = null; if (type != null) { result = new ClassMetadata { EntityType = type, EntityName = type.Name }; var at = type.GetCustomAttributes(false); if (at.Length > 0) { var tableAttribute = (TableAttribute)at[0]; result.TableName = tableAttribute.Name; result.TableName = tableAttribute.Name; result.AssociateTable = tableAttribute.AssociateTable; result.ForeignKey = tableAttribute.ForeignKey; } var columnInfos = new List<ColumnInfo>(); var propertyInfos = type.GetProperties(); ColumnInfo model; foreach (var info in propertyInfos) { model = new ColumnInfo { PropertyInfo = info }; var attributes = info.GetCustomAttributes(false); foreach (var att in attributes) { if (att is ColumnAttribute) { var ptt = att as ColumnAttribute; model.PropertyName = info.Name; model.PropertyType = info.PropertyType.IsGenericType && info.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) ? info.PropertyType.GetGenericArguments()[0] : info.PropertyType; if (ptt.IsPrimaryKey) { result.PrimaryKey = info.Name; result.PKColumnName = ptt.Name; } model.IsIncrement = ptt.IsIncrement; model.IsNullable = ptt.IsNullable; model.IsUnique = ptt.IsUnique; model.ParameterDirection = ptt.ParameterDirection; model.SameParameters = ptt.SameParameters; model.IsColumn = true; model.Name = ptt.Name; model.IsPrimaryKey = ptt.IsPrimaryKey; model.IsInsertable = ptt.IsInsertable; model.IsUpdatable = ptt.IsUnique; model.ColumnDefinition = ptt.ColumnDefinition; model.Table = ptt.Table; model.Length = ptt.Length; model.Precision = ptt.Precision; model.Scale = ptt.Scale; } else { //break; } } if (info.DeclaringType != typeof(IEntity)) columnInfos.Add(model); } result.ColumnInfos = columnInfos; } return result; }
private string OperationToString(ClassMetadata classMetadata) { var result = new StringBuilder(); var columnName = ""; var parameters = new List<DbParameter>(); foreach (ColumnInfo columnInfo in classMetadata.ColumnInfos) { if (!columnInfo.IsColumn) continue; if (columnInfo.PropertyName.ToUpper() == Name.ToUpper()) { columnName = columnInfo.Name; } //if (IsNull(value)) continue; //if (IsNullValue(value) && columnInfo.IsNullable) continue; //var index = Contains(obj.Conditaion, columnInfo.PropertyName); //if (index == 0) //{ // rConditaion = rConditaion.Replace(string.Format(LikeString[0], columnInfo.PropertyName), entityPersister.Driver.FormatNameForSql(columnInfo.Name)); // entityPersister.SetDbParamter(session, parameters, columnInfo.Name, value); // //entityPersister.SetDbParamter(session, parameters, classMetadata.PrimaryKey, value); //} //else if (index > 0) //{ // rConditaion = rConditaion.Replace(string.Format(LikeString[index], columnInfo.PropertyName), string.Format(LikeValueString[index - 1], Escape(value.ToString(), ""))); //} } var paramName = Driver.FormatNameForSql(columnName); switch (Operation) { case OP.EQ: result.Append(columnName).Append("=").Append(paramName); SetDbParamter(DbParameter, columnName, Value); break; case OP.NE: result.Append(columnName).Append("<>").Append(paramName); SetDbParamter(DbParameter, columnName, Value); break; case OP.GE: result.Append(columnName).Append(">=").Append(paramName); SetDbParamter(DbParameter, columnName, Value); break; case OP.LE: result.Append(columnName).Append("<=").Append(paramName); SetDbParamter(DbParameter, columnName, Value); break; case OP.GT: result.Append(columnName).Append(">").Append(paramName); SetDbParamter(DbParameter, columnName, Value); break; case OP.LT: result.Append(columnName).Append("<").Append(paramName); SetDbParamter(DbParameter, columnName, Value); break; // case OP.BETWEEN: // String min = new StringBuilder("min").append(propertyName).toString(); // String max = new StringBuilder("max").append(propertyName).toString(); // sql.append("(").append(columnName).append(">=").append(prefixInSql).append(min); // sql.append(" AND "); // sql.append(columnName).append("<=").append(prefixInSql).append(max).append(")"); // Object[] v = ArrayUtil.toObjectArray(value); // parameterMap.put(min, new SqlParameter(min, v[0], typeName, sqlType, scale)); // parameterMap.put(max, new SqlParameter(max, v[1], typeName, sqlType, scale)); // break; //case OP.IN: // result.Append(columnName).Append(" IN (").Append(paramName).Append(") "); // SetDbParamter(DbParameter, columnName, Value); // //sql.append(columnName).append(" IN ("); // ////如果数据库是Oralce时,使用时注意In表达式内的变量数在100之内,当变量数大于100时建议客户程序分批处理。 // //buildInOperation(sql);//update by LDG, // ////buildInOperation(prefixInSql, sql, typeName, sqlType, scale, propertyName); // //sql.append(") "); // break; // case OP.NOTIN: // sql.append(columnName).append(" NOT IN ("); // buildInOperation(sql); // //buildInOperation(prefixInSql, sql, typeName, sqlType, scale, propertyName); // sql.append(") "); // break; case OP.LIKE: result.Append(columnName).Append(" LIKE ").Append(paramName); SetDbParamter(DbParameter, columnName, string.Format("%{0}%",Value)); break; case OP.FLIKE: result.Append(columnName).Append(" LIKE ").Append(paramName); SetDbParamter(DbParameter, columnName, string.Format("{0}%", Value)); break; case OP.ELIKE: result.Append(columnName).Append(" LIKE ").Append(paramName); SetDbParamter(DbParameter, columnName, string.Format("%{0}", Value)); break; //case OP.IS: // result.Append(columnName).Append(" IS ").Append(paramName); // SetDbParamter(DbParameter, columnName, Value); // break; //case OP.UEMPTY: // result.Append(columnName).Append(" IS NOT NULL"); // break; } return result.ToString(); }
public string ToString(ClassMetadata classMetadata) { var result = new StringBuilder(); if (Value is Criteria) { var criteria = Value as Criteria; result.Append(criteria.ToString(classMetadata)); } else { result.Append(OperationToString(classMetadata)); } return result.ToString(); }
public string ToString(ClassMetadata classMetadata) { var result = new StringBuilder(); var index = 0; foreach (var criterion in this.CriterionList) { criterion.Driver = this.Driver; criterion.DicParameter = this.DicParameter; criterion.DbParameter = this.DbParameter; if (index > 0) { result.Append(criterion.LogicOperation == LOP.OR?" OR ":" AND "); } result.Append(criterion.ToString(classMetadata)); index++; } return result.ToString(); }