private void WriteGetListBy(IEnumerable <DatabaseColumn> columns)
        {
            var methodParameters = CodeWriterUtils.GetMethodParametersForColumns(columns, codeWriterSettings);

            WriteGetListByMethodSummary(methodParameters);
            var methodSignature = CodeWriterUtils.GetGetListByMethodSignature(table, columns, codeWriterSettings, methodParameters);

            using (classBuilder.BeginNest($"public {methodSignature}"))
            {
                CodeWriterUtils.WriteEntryLogging(classBuilder, methodSignature);
                var sqlCommandText = ConstructSqlQuery(methodParameters, null, GetAllColumnNames(new List <DatabaseTable> {
                    table
                }));
                classBuilder.AppendLine($"var entities = new List<{table.NetName}>();");
                WriteBeginCreateConnection();
                WriteBeginCreateCommand();
                classBuilder.AppendLine($"command.CommandText = {sqlCommandText};");
                WriteAddParametersToCommand(methodParameters);
                WriteBeginExecuteReader();
                WriteBeginReadReaderMultiple();
                classBuilder.AppendLine($"var entity = ({table.NetName}){_serviceProviderFieldName}.GetService(typeof({table.NetName}));");
                WriteParseEntityFromReader("entity");
                classBuilder.AppendLine("entities.Add(entity);");
                classBuilder.EndNest();
                classBuilder.EndNest();
                classBuilder.EndNest();
                classBuilder.EndNest();
                classBuilder.AppendLine("");
                classBuilder.AppendLine("return entities;");
                CodeWriterUtils.WriteExitLogging(classBuilder, methodSignature);
            }
        }
Пример #2
0
        private void WriteGetListBys()
        {
            var combinations = CodeWriterUtils.GetGetListByColumnCombinations(table)?.ToList();

            combinations?.ForEach(c => classBuilder.AppendLine($"{CodeWriterUtils.GetGetListByMethodSignature(table, c, codeWriterSettings, CodeWriterUtils.GetMethodParametersForColumns(c, codeWriterSettings))};"));
        }