void WriteSelectByIndexMethods() { var typeContractName = TableEntityClassNameForMethodParametersInRepositoryFiles; foreach (var indexIdentifier in TableInfo.UniqueIndexInfoList) { var indexInfo = SelectByIndexInfoCreator.Create(TableInfo, indexIdentifier); var parameterDefinitionPart = string.Join(", ", indexInfo.SqlParameters.Select(x => $"{x.DotNetType} {x.ColumnName.AsMethodParameter()}")); var methodName = "SelectBy" + string.Join(string.Empty, indexInfo.SqlParameters.Select(x => $"{x.ColumnName.ToContractName()}")); file.AppendLine(); file.AppendLine("/// <summary>"); file.AppendLine($"///{Padding.ForComment} Selects records by given parameters."); file.AppendLine("/// </summary>"); file.AppendLine($"public GenericResponse<{typeContractName}> {methodName}({parameterDefinitionPart})"); file.OpenBracket(); var sharedMethodInvocationParameters = string.Join(", ", indexInfo.SqlParameters.Select(x => $"{x.ColumnName.AsMethodParameter()}")); var callerMemberPath = $"{RepositoryNamespace}.{ClassName}.{methodName}"; file.AppendLine($"var sqlInfo = {sharedRepositoryClassAccessPath}.{methodName}({sharedMethodInvocationParameters});"); file.AppendLine(); file.AppendLine($"const string CallerMemberPath = \"{callerMemberPath}\";"); file.AppendLine(); file.AppendLine($"return this.ExecuteReaderToContract<{typeContractName}>( CallerMemberPath, sqlInfo, {sharedRepositoryClassAccessPath}.ReadContract);"); file.CloseBracket(); } foreach (var indexIdentifier in TableInfo.NonUniqueIndexInfoList) { var indexInfo = SelectByIndexInfoCreator.Create(TableInfo, indexIdentifier); var parameterDefinitionPart = string.Join(", ", indexInfo.SqlParameters.Select(x => $"{x.DotNetType} {x.ColumnName.AsMethodParameter()}")); var methodName = "SelectBy" + string.Join(string.Empty, indexInfo.SqlParameters.Select(x => $"{x.ColumnName.ToContractName()}")); var callerMemberPath = $"{RepositoryNamespace}.{ClassName}.{methodName}"; file.AppendLine(); file.AppendLine("/// <summary>"); file.AppendLine($"///{Padding.ForComment} Selects records by given parameters."); file.AppendLine("/// </summary>"); file.AppendLine($"public GenericResponse<List<{typeContractName}>> {methodName}({parameterDefinitionPart})"); file.OpenBracket(); var sharedMethodInvocationParameters = string.Join(", ", indexInfo.SqlParameters.Select(x => $"{x.ColumnName.AsMethodParameter()}")); file.AppendLine($"var sqlInfo = {sharedRepositoryClassAccessPath}.{methodName}({sharedMethodInvocationParameters});"); file.AppendLine(); file.AppendLine($"const string CallerMemberPath = \"{callerMemberPath}\";"); file.AppendLine(); file.AppendLine($"return this.ExecuteReaderToList<{typeContractName}>(CallerMemberPath, sqlInfo, {sharedRepositoryClassAccessPath}.ReadContract);"); file.CloseBracket(); } }
void WriteSelectByIndexMethods() { var allIndexes = new List <IIndexInfo>(); allIndexes.AddRange(TableInfo.NonUniqueIndexInfoList); allIndexes.AddRange(TableInfo.UniqueIndexInfoList); foreach (var indexIdentifier in allIndexes) { var indexInfo = SelectByIndexInfoCreator.Create(TableInfo, indexIdentifier); var methodName = GetMethodName(indexInfo); var parameterPart = string.Join(", ", indexInfo.SqlParameters.Select(x => $"{x.DotNetType} {x.ColumnName.AsMethodParameter()}")); file.AppendLine(); file.AppendLine("/// <summary>"); file.AppendLine($"///{Padding.ForComment} Selects records by given parameters."); file.AppendLine("/// </summary>"); file.AppendLine($"public static SqlInfo {methodName}({parameterPart})"); file.OpenBracket(); file.AppendLine("const string sql = @\""); file.AppendAll(indexInfo.Sql); file.AppendLine(); file.AppendLine("\";"); file.AppendLine(); file.AppendLine("var sqlInfo = new SqlInfo { CommandText = sql };"); if (indexInfo.SqlParameters.Any()) { file.AppendLine(); foreach (var columnInfo in indexInfo.SqlParameters) { file.AppendLine($"sqlInfo.AddInParameter(\"@{columnInfo.ColumnName}\", SqlDbType.{columnInfo.SqlDbType}, {GetValueAccessPath(columnInfo)});"); } } file.AppendLine(); file.AppendLine("return sqlInfo;"); file.CloseBracket(); } }