void WriteSelectByKeyMethod() { if (!TableInfo.IsSupportSelectByKey) { return; } var typeContractName = TableEntityClassNameForMethodParametersInRepositoryFiles; var selectByPrimaryKeyInfo = SelectByPrimaryKeyInfoCreator.Create(TableInfo); var sqlParameters = selectByPrimaryKeyInfo.SqlParameters; var parameterDefinitionPart = string.Join(", ", sqlParameters.Select(x => $"{x.DotNetType} {x.ColumnName.AsMethodParameter()}")); var methodName = "Get" + CamelCasedTableName + "By" + string.Join(string.Empty, sqlParameters.Select(x => $"{x.ColumnName.ToContractName()}")); // var methodName = "Get" + CamelCasedTableName + "ByKey"; var callerMemberPath = $"{FullClassName}.{methodName}"; file.AppendLine(); file.AppendLine($"public {typeContractName} {methodName}({parameterDefinitionPart})"); file.OpenBracket(); var sharedMethodInvocationParameters = string.Join(", ", sqlParameters.Select(x => $"{x.ColumnName.AsMethodParameter()}")); file.AppendLine($"var sqlInfo = {sharedRepositoryClassAccessPath}.SelectByKey({sharedMethodInvocationParameters});"); file.AppendLine(); file.AppendLine($"const string CallerMemberPath = \"{callerMemberPath}\";"); file.AppendLine(); file.AppendLine($"return unitOfWork.ExecuteReaderToContract<{typeContractName}>(CallerMemberPath, sqlInfo, {sharedRepositoryClassAccessPath}.ReadContract);"); file.CloseBracket(); }
void WriteSelectByKeyMethod() { var selectByPrimaryKeyInfo = SelectByPrimaryKeyInfoCreator.Create(TableInfo); var sqlParameters = selectByPrimaryKeyInfo.SqlParameters; var parameterPart = string.Join(", ", sqlParameters.Select(x => $"{x.DotNetType} {x.ColumnName.AsMethodParameter()}")); file.AppendLine($"public static SqlInfo SelectByKey({parameterPart})"); file.OpenBracket(); file.AppendLine("const string sql = @\""); file.AppendAll(selectByPrimaryKeyInfo.Sql); file.AppendLine(); file.AppendLine("\";"); file.AppendLine(); file.AppendLine("var sqlInfo = new SqlInfo { CommandText = sql };"); if (sqlParameters.Any()) { file.AppendLine(); foreach (var columnInfo in sqlParameters) { file.AppendLine($"sqlInfo.AddInParameter(\"@{columnInfo.ColumnName}\", SqlDbType.{columnInfo.SqlDbType}, {GetValueAccessPath(columnInfo)});"); } } file.AppendLine(); file.AppendLine("return sqlInfo;"); file.CloseBracket(); }
void WriteSelectByKeyMethod() { if (!TableInfo.IsSupportSelectByKey) { return; } var typeContractName = TableEntityClassNameForMethodParametersInRepositoryFiles; var selectByPrimaryKeyInfo = SelectByPrimaryKeyInfoCreator.Create(TableInfo); var callerMemberPath = $"{RepositoryNamespace}.{ClassName}.SelectByKey"; var parameterPart = string.Join(", ", selectByPrimaryKeyInfo.SqlParameters.Select(x => $"{x.DotNetType} {x.ColumnName.AsMethodParameter()}")); file.AppendLine(); file.AppendLine("/// <summary>"); file.AppendLine($"///{Padding.ForComment} Selects record by primary keys."); file.AppendLine("/// </summary>"); file.AppendLine($"public GenericResponse<{typeContractName}> SelectByKey({parameterPart})"); file.AppendLine("{"); file.PaddingCount++; file.AppendLine($"var sqlInfo = {sharedRepositoryClassAccessPath}.SelectByKey({string.Join(", ", selectByPrimaryKeyInfo.SqlParameters.Select(x => $"{x.ColumnName.AsMethodParameter()}"))});"); file.AppendLine(); file.AppendLine($"const string CallerMemberPath = \"{callerMemberPath}\";"); file.AppendLine(); file.AppendLine($"return this.ExecuteReaderToContract<{typeContractName}>(CallerMemberPath, sqlInfo, {sharedRepositoryClassAccessPath}.ReadContract);"); file.PaddingCount--; file.AppendLine("}"); }