public void Process(DbCommand command, object model) { Command = command; sqlWriter = new SqlWriter(); Smart = new SmartBuilder(sqlWriter); parametersIndex = 0; if (model != null) { var modelType = model.GetType(); var typeInfo = modelType.GetTypeInfo(); if (typeInfo.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Any() && modelType.FullName.Contains("AnonymousType")) { IDictionary <string, object> expando = new ExpandoObject(); foreach (var propertyDescriptor in typeInfo.GetProperties()) { var obj = propertyDescriptor.GetValue(model); expando.Add(propertyDescriptor.Name, obj); } Model = (TModel)expando; } else { Model = (TModel)model; } } Execute(); var sql = sqlWriter.ToString(); if (logger != null) { logger.LogInformation(sql); logger.LogInformation(string.Join('\n', Command.Parameters.OfType <DbParameter>().Select(e => $"{e.ParameterName} -> {e.Value}"))); } command.CommandText = sql; }
internal SmartSet(SqlWriter sqlWriter) { sqlWriter.CreateContext(); SqlWriter = sqlWriter; }