protected override Expression VisitMember(MemberExpression expression) { var type = expression.Type; if (expression.Expression != null && expression.Expression.NodeType == ExpressionType.Parameter) { var memberName = expression.Member.Name; var columnName = _mappingRuleTranslator.GetColumnName(_genericType, memberName); _builder.Append(columnName); } return(expression); }
/// <summary> /// Visit a member access expression and fill in the sql script. /// </summary> /// <param name="expression"></param> /// <returns></returns> protected override Expression VisitMember(MemberExpression expression) { var memberName = expression.Member.Name; var columnName = _mappingRuleTranslator.GetColumnName(_genericType, memberName); _builder.Append(columnName); return(expression); }
/// <summary> /// Visit the constant expression and fill in the T-SQL script. /// </summary> /// <param name="expression"></param> /// <returns></returns> protected override Expression VisitConstant(ConstantExpression expression) { var value = expression.Value; var type = expression.Type; var properties = type.GetProperties(); var columnNames = new List <string>(); var columnValues = new List <string>(); foreach (var property in properties) { var columnName = _mappingRuleTranslator.GetColumnName(type, property.Name); var columnValue = property.GetValue(value); var columnType = _mappingRuleTranslator.GetColumnDefinition(type, property.Name).Type; columnNames.Add(columnName); columnValues.Add(GenerateSqlScriptHelper.ConvertConstantIntoSqlScript(columnType, columnValue)); } var sqlRequest = string.Format("({0}) VALUES ({1})", string.Join(",", columnNames), string.Join(",", columnValues)); _builder.Append(sqlRequest); return(expression); }