Skip to content

Commit

Permalink
Fxi stringlength issues (#2698)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ authored Dec 3, 2024
1 parent ce656a0 commit ee030a5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,11 @@ private void GenerateProperties(List<ModuleResultElement> resultElements, bool n
}

if (useDecimalDataAnnotation
&& ((property.StoreType.StartsWith("varchar", StringComparison.OrdinalIgnoreCase)
&& ((property.StoreType.StartsWith("varchar", StringComparison.OrdinalIgnoreCase)
|| property.StoreType.StartsWith("nvarchar", StringComparison.OrdinalIgnoreCase))
&& property.MaxLength > 0))
{
var maxLength = property.StoreType.StartsWith("varchar", StringComparison.OrdinalIgnoreCase) ? property.MaxLength : property.MaxLength / 2;

Sb.AppendLine($"[StringLength({maxLength})]");
Sb.AppendLine($"[StringLength({property.MaxLength})]");
}

var propertyType = typeMapper.GetClrType(property);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,23 @@ FROM sys.columns c
{
if (res != null)
{
var storeType = res["type_name"].ToString();
var maxLength = res["max_length"] == DBNull.Value ? 0 : int.Parse(res["max_length"].ToString()!, CultureInfo.InvariantCulture);

if (storeType != null
&& storeType.StartsWith("nvarchar", StringComparison.OrdinalIgnoreCase)
&& maxLength > 0)
{
maxLength = maxLength / 2;
}

var parameter = new ModuleResultElement()
{
Name = string.IsNullOrEmpty(res["name"].ToString()) ? $"Col{rCounter}" : res["name"].ToString(),
StoreType = res["type_name"].ToString(),
StoreType = storeType,
Ordinal = int.Parse(res["column_ordinal"].ToString()!, CultureInfo.InvariantCulture),
Nullable = (bool)res["is_nullable"],
MaxLength = res["max_length"] == DBNull.Value ? 0 : int.Parse(res["max_length"].ToString()!, CultureInfo.InvariantCulture),
MaxLength = maxLength,
};

list.Add(parameter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,7 @@ private void GenerateProperties(List<ModuleResultElement> resultElements, bool n
|| property.StoreType.StartsWith("nvarchar", StringComparison.OrdinalIgnoreCase))
&& property.MaxLength > 0))
{
var maxLength = property.StoreType.StartsWith("varchar", StringComparison.OrdinalIgnoreCase) ? property.MaxLength : property.MaxLength / 2;

Sb.AppendLine($"[StringLength({maxLength})]");
Sb.AppendLine($"[StringLength({property.MaxLength})]");
}

var propertyType = typeMapper.GetClrType(property);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,23 @@ private static List<List<ModuleResultElement>> GetFirstResultSet(SqlConnection c
continue;
}

var storeType = string.IsNullOrEmpty(row["system_type_name"].ToString()) ? row["user_type_name"].ToString() : row["system_type_name"].ToString();
var maxLength = row["max_length"] == DBNull.Value ? 0 : int.Parse(row["max_length"].ToString()!, CultureInfo.InvariantCulture);

if (storeType != null
&& storeType.StartsWith("nvarchar", StringComparison.OrdinalIgnoreCase)
&& maxLength > 0)
{
maxLength = maxLength / 2;
}

var parameter = new ModuleResultElement()
{
Name = name,
StoreType = string.IsNullOrEmpty(row["system_type_name"].ToString()) ? row["user_type_name"].ToString() : row["system_type_name"].ToString(),
StoreType = storeType,
Ordinal = int.Parse(row["column_ordinal"].ToString()!, CultureInfo.InvariantCulture),
Nullable = (bool)row["is_nullable"],
MaxLength = row["max_length"] == DBNull.Value ? 0 : int.Parse(row["max_length"].ToString()!, CultureInfo.InvariantCulture),
MaxLength = maxLength,
};

list.Add(parameter);
Expand Down
Binary file modified src/GUI/lib/efreveng80.exe.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace ScaffoldingTester.Models
public partial class MultiSetResult
{
public int ShipperID { get; set; }
[StringLength(40)]
public string CompanyName { get; set; }
[StringLength(24)]
public string Phone { get; set; }
}
}

0 comments on commit ee030a5

Please sign in to comment.