public ICondition Or(ICondition conditionExpression) { ConditionExpressionCollection cs = new ConditionExpressionCollection(); cs.ConditionRelation = ConditionRelation.Or; cs.Add(this); if (conditionExpression is IConditionExpression) { cs.Add(conditionExpression); } else { IConditionExpressionCollection conditionCollection = (IConditionExpressionCollection)conditionExpression; if (conditionCollection.ConditionRelation == ConditionRelation.Or) { foreach (ICondition item in conditionCollection) { cs.Add(item); } } else { cs.Add(conditionCollection); } } return(cs); }
public ICondition Or(ICondition conditionExpression) { if (ConditionRelation == ConditionRelation.Or) { if (conditionExpression is IConditionExpression) { Add(conditionExpression); } else { IConditionExpressionCollection conditionCollection = (IConditionExpressionCollection)conditionExpression; if (conditionCollection.ConditionRelation == ConditionRelation.Or) { foreach (ICondition item in conditionCollection) { Add(item); } } else { Add(conditionCollection); } } } else { IConditionExpressionCollection cs = Copy(); Items.Clear(); Add(cs); ConditionRelation = ConditionRelation.Or; if (conditionExpression is IConditionExpression) { Add(conditionExpression); } else { IConditionExpressionCollection conditionCollection = (IConditionExpressionCollection)conditionExpression; if (conditionCollection.ConditionRelation == ConditionRelation.Or) { foreach (ICondition item in conditionCollection) { Add(item); } } else { Add(conditionCollection); } } } return(this); }
public void Add(ICondition conditionExpression) { if (conditionExpression is ConditionExpression) { Items.Add(conditionExpression); } else { IConditionExpressionCollection conditionCollection = (IConditionExpressionCollection)conditionExpression; if (ConditionRelation == ConditionRelation.And) { if (conditionCollection.ConditionRelation == ConditionRelation.And) { foreach (ICondition item in conditionCollection) { Add(item); } } else { Items.Add(conditionCollection); } } else { if (conditionCollection.ConditionRelation == ConditionRelation.Or) { foreach (ICondition item in conditionCollection) { Add(item); } } else { Items.Add(conditionCollection); } } } }
private static void CollectPropertyNames(SortedDictionary <IPropertyExpression, string> taskPropertyNames, ICondition wheres) { if (wheres != null) { if (wheres is IConditionExpressionCollection) { IConditionExpressionCollection conditionCollection = (IConditionExpressionCollection)wheres; foreach (ICondition obj in conditionCollection) { CollectPropertyNames(taskPropertyNames, obj); } } else { IConditionExpression conditionItem = (IConditionExpression)wheres; if (!taskPropertyNames.ContainsKey(conditionItem.Property)) { taskPropertyNames.Add(conditionItem.Property, null); } } } }
//生成包含关联表的select语句的 where 部分 protected virtual void GenerateSelectSql_Where( StringBuilder sb, IDataParameterCollection parameters, ref int parameterCounter, ICondition condition, SqlAnalyseResult sqlAnalyseResult, bool includeTableNameAlias, IMappingProvider mappingProvider ) { if (condition is IConditionExpressionCollection) { IConditionExpressionCollection conditions = (IConditionExpressionCollection)condition; string andOr = conditions.ConditionRelation == ConditionRelation.And ? " and " : " or "; if (conditions.Count > 1) { sb.Append("("); } int index = 0; foreach (ICondition conditionItem in conditions) { if (index > 0) { sb.Append(andOr); } index++; GenerateSelectSql_Where(sb, parameters, ref parameterCounter, conditionItem, sqlAnalyseResult, includeTableNameAlias, mappingProvider); } if (conditions.Count > 1) { sb.Append(") "); } } else { IConditionExpression conditionItem = (IConditionExpression)condition; SqlColumn sqlColumn = sqlAnalyseResult.SqlColumns[conditionItem.Property]; GenerateSelectSql_Where_Item(sb, parameters, ref parameterCounter, conditionItem, sqlColumn, includeTableNameAlias, mappingProvider); } }