private TranslateResult TranslateWhere(object instance, Type type, List <Parameter> parameters) { bool isFirst = true; TableSchema tableSchema = TableSchemaResolver.GetTableSchema(type); int paramIndex = 0; for (int i = 0, count = tableSchema.FieldsSchema.Count; i < count; i++) { var field = tableSchema.FieldsSchema[i]; if (field.IsPrimaryKey || field.IsUpdCount) { object value = ExpressionFunc.GetPropertyValue(instance, type, field.PropertyInfo); if (value == null) { throw new NotSupportedException(string.Format("The field '{0}' is not supported", field.FieldName)); } if (!isFirst) { clauseBuilder.AppendClause(" And "); } clauseBuilder.AppendClause(field.FieldName); clauseBuilder.AppendClause("="); if (parameters == null) { clauseBuilder.AppendClause(parameterBuilder.GenerateParameterName(), value); } else { clauseBuilder.AppendClause(parameters[paramIndex++].Name, value); } isFirst = false; } } return(new TranslateResult { CommandText = clauseBuilder.GetExpressionText(), // UPDATE ...Where key_column=some_value And UpdCount=some_value // DELETE ...Where key_column=some_value And UpdCount=some_value Parameters = clauseBuilder.GetExpressionParameters(), }); }
protected override Expression VisitUnary(UnaryExpression node) { switch (node.NodeType) { case ExpressionType.Not: clauseBuilder.AppendClause(" NOT "); this.Visit(node.Operand); break; case ExpressionType.Convert: this.Visit(node.Operand); break; default: throw new NotSupportedException(string.Format("The unary operator '{0}' is not suported", node.NodeType)); } return(node); }