private void WriteCreate()
        {
            var methodParameters = CodeWriterUtils.GetCreateMethodParameters(table).ToList();

            WriteCreateMethodSummary(methodParameters);
            var methodSignature = CodeWriterUtils.GetCreateMethodSignature(table, methodParameters);

            using (classBuilder.BeginNest($"public {methodSignature}"))
            {
                CodeWriterUtils.WriteEntryLogging(classBuilder, methodSignature);
                WriteGetPropertyColumnPairs();
                classBuilder.AppendLine("var valuesClause = string.Join(\", \", propertyColumnPairs.Keys.Select(k => \"@\" + k.Name));");
                var thisTableAlias = codeWriterSettings.Namer.NameToAcronym(table.Name);
                classBuilder.AppendLine($"var sqlCommandText = $\"INSERT INTO \\\"{table.Name}\\\" AS {thisTableAlias} ({{string.Join(\", \", propertyColumnPairs.Values)}}) VALUES ({{valuesClause}}) RETURNING {GetAllColumnNames(new List<DatabaseTable> { table })};\";");
                var entityVariableName = "createdEntity";
                classBuilder.AppendLine($"{table.NetName} {entityVariableName} = null;");
                WriteBeginCreateConnection();
                WriteBeginCreateCommand();
                classBuilder.AppendLine($"command.CommandText = sqlCommandText;");
                WriteAddParametersToCommand();
                classBuilder.BeginNest("try");
                WriteBeginExecuteReader();
                WriteBeginReadReaderSingle();
                classBuilder.AppendLine($"{entityVariableName} = ({table.NetName}){_serviceProviderFieldName}.GetService(typeof({table.NetName}));");
                WriteParseEntityFromReader(entityVariableName);
                classBuilder.EndNest();
                classBuilder.EndNest();
                classBuilder.EndNest();
                WriteCatchPostgresExceptions();
                classBuilder.EndNest();
                classBuilder.EndNest();
                WriteReturnEntityIfNotNull(entityVariableName);
                CodeWriterUtils.WriteExitLogging(classBuilder, methodSignature);
            }

            classBuilder.AppendLine("");
        }
Exemple #2
0
 private void WriteCreate()
 {
     classBuilder.AppendLine($"{CodeWriterUtils.GetCreateMethodSignature(table, CodeWriterUtils.GetCreateMethodParameters(table))};");
 }