diff --git a/src/Core/RevEng.Core.80/Routines/Functions/SqlServerFunctionModelFactory.cs b/src/Core/RevEng.Core.80/Routines/Functions/SqlServerFunctionModelFactory.cs index 4ee1a017c..dde62163c 100644 --- a/src/Core/RevEng.Core.80/Routines/Functions/SqlServerFunctionModelFactory.cs +++ b/src/Core/RevEng.Core.80/Routines/Functions/SqlServerFunctionModelFactory.cs @@ -1,4 +1,4 @@ -using Microsoft.Data.SqlClient; +using Microsoft.Data.SqlClient; using RevEng.Core.Abstractions; using RevEng.Core.Abstractions.Metadata; using RevEng.Core.Abstractions.Model; @@ -50,7 +50,8 @@ protected override List> GetResultElementLists(SqlConn c.name, COALESCE(ts.name, tu.name) AS type_name, c.column_id AS column_ordinal, - c.is_nullable + c.is_nullable, + c.max_length FROM sys.columns c inner join sys.types tu ON c.user_type_id = tu.user_type_id inner join sys.objects AS o on o.object_id = c.object_id @@ -79,6 +80,7 @@ FROM sys.columns c StoreType = res["type_name"].ToString(), Ordinal = int.Parse(res["column_ordinal"].ToString()!, CultureInfo.InvariantCulture), Nullable = (bool)res["is_nullable"], + MaxLength = res["max_length"] == DBNull.Value ? (short)0 : short.Parse(res["max_length"].ToString()!, CultureInfo.InvariantCulture), }; list.Add(parameter); diff --git a/src/Core/RevEng.Core.80/Routines/Procedures/SqlServerStoredProcedureModelFactory.cs b/src/Core/RevEng.Core.80/Routines/Procedures/SqlServerStoredProcedureModelFactory.cs index 1a75b15d3..f01862e91 100644 --- a/src/Core/RevEng.Core.80/Routines/Procedures/SqlServerStoredProcedureModelFactory.cs +++ b/src/Core/RevEng.Core.80/Routines/Procedures/SqlServerStoredProcedureModelFactory.cs @@ -1,4 +1,4 @@ -using Microsoft.Data.SqlClient; +using Microsoft.Data.SqlClient; using RevEng.Core.Abstractions; using RevEng.Core.Abstractions.Metadata; using RevEng.Core.Abstractions.Model; @@ -126,6 +126,7 @@ private static List> GetAllResultSets(SqlConnection co StoreType = storeType, Precision = (short?)row["NumericPrecision"], Scale = (short?)row["NumericScale"], + MaxLength = (short)row["ColumnSize"], }); } } @@ -183,6 +184,7 @@ private static List> GetFirstResultSet(SqlConnection c StoreType = string.IsNullOrEmpty(row["system_type_name"].ToString()) ? row["user_type_name"].ToString() : row["system_type_name"].ToString(), Ordinal = int.Parse(row["column_ordinal"].ToString()!, CultureInfo.InvariantCulture), Nullable = (bool)row["is_nullable"], + MaxLength = row["max_length"] == DBNull.Value ? (short)0 : short.Parse(row["max_length"].ToString()!, CultureInfo.InvariantCulture), }; list.Add(parameter); diff --git a/src/Core/RevEng.Core.80/Routines/RoutineScaffolder.cs b/src/Core/RevEng.Core.80/Routines/RoutineScaffolder.cs index 7c43178c0..3ba9b7dd0 100644 --- a/src/Core/RevEng.Core.80/Routines/RoutineScaffolder.cs +++ b/src/Core/RevEng.Core.80/Routines/RoutineScaffolder.cs @@ -313,6 +313,13 @@ private void GenerateProperties(List resultElements, bool n } } + if (useDecimalDataAnnotation + && (property.StoreType == "varchar" || property.StoreType == "nvarchar") + && property.MaxLength > 0) + { + Sb.AppendLine($"[StringLength({property.MaxLength})]"); + } + var propertyType = typeMapper.GetClrType(property); var nullableAnnotation = string.Empty; var defaultAnnotation = string.Empty; diff --git a/src/Core/RevEng.Core.Abstractions/Metadata/ModuleResultElement.cs b/src/Core/RevEng.Core.Abstractions/Metadata/ModuleResultElement.cs index f64d7b158..fa94f4cf4 100644 --- a/src/Core/RevEng.Core.Abstractions/Metadata/ModuleResultElement.cs +++ b/src/Core/RevEng.Core.Abstractions/Metadata/ModuleResultElement.cs @@ -8,5 +8,6 @@ public class ModuleResultElement public bool Nullable { get; set; } public short? Precision { get; set; } public short? Scale { get; set; } + public short MaxLength { get; set; } } }