Skip to content

Commit 1622902

Browse files
committed
Update template
1 parent 334c2a7 commit 1622902

File tree

1 file changed

+54
-15
lines changed

1 file changed

+54
-15
lines changed

EntityFramework.Reverse.POCO.Generator/EF.Reverse.POCO.v3.ttinclude

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,13 @@
385385
if (column.IsRowVersion)
386386
column.Attributes.Add("[Timestamp, ConcurrencyCheck]");
387387

388-
if (!column.IsMaxLength && column.MaxLength > 0)
388+
// SQL Server 2025 vector type - use [Column(TypeName = "vector(n)")] instead of MaxLength
389+
var isVectorType = column.SqlPropertyType != null && column.SqlPropertyType.StartsWith("vector", StringComparison.InvariantCultureIgnoreCase);
390+
if (isVectorType)
391+
{
392+
column.Attributes.Add(string.Format("[Column(TypeName = \"{0}\")]", column.SqlPropertyType));
393+
}
394+
else if (!column.IsMaxLength && column.MaxLength > 0)
389395
{
390396
var doNotSpecifySize = (DatabaseType == DatabaseType.SqlCe && column.MaxLength > 4000);
391397
column.Attributes.Add(doNotSpecifySize ? "[MaxLength]" : string.Format("[MaxLength({0})]", column.MaxLength));
@@ -3985,6 +3991,7 @@
39853991
BaseClasses = table.BaseClasses,
39863992
InsideClassBody = Settings.WriteInsideClassBody(table),
39873993
HasHierarchyId = table.Columns.Any(x => x.PropertyType.EndsWith("hierarchyid", StringComparison.InvariantCultureIgnoreCase)),
3994+
HasSqlVector = table.Columns.Any(x => x.PropertyType.StartsWith("SqlVector", StringComparison.InvariantCultureIgnoreCase)),
39883995
Columns = columnsQuery
39893996
.Where(x => !x.Hidden && !x.ExistsInBaseClass)
39903997
.Select((col, index) => new PocoColumnModel
@@ -6365,13 +6372,14 @@
63656372
doNotSpecifySize = (DatabaseReader.DoNotSpecifySizeForMaxLength && c.MaxLength > 4000); // Issue #179
63666373

63676374
var excludedHasColumnType = string.Empty;
6375+
var isVectorType = c.SqlPropertyType != null && c.SqlPropertyType.StartsWith("vector", StringComparison.InvariantCultureIgnoreCase);
63686376
if (!string.IsNullOrEmpty(c.SqlPropertyType))
63696377
{
63706378
var columnTypeParameters = string.Empty;
63716379

63726380
if ((c.Precision > 0 || c.Scale > 0) && (c.SqlPropertyType == "decimal" || c.SqlPropertyType == "numeric"))
63736381
columnTypeParameters = $"({c.Precision},{c.Scale})";
6374-
else if (!c.IsMaxLength && c.MaxLength > 0 && !doNotSpecifySize)
6382+
else if (!c.IsMaxLength && c.MaxLength > 0 && !doNotSpecifySize && !isVectorType) // Vector types already include dimension in SqlPropertyType
63756383
columnTypeParameters = $"({c.MaxLength})";
63766384

63776385
if (Column.ExcludedHasColumnType.Contains(c.SqlPropertyType))
@@ -6401,7 +6409,7 @@
64016409
if (!c.IsUnicode)
64026410
sb.Append(".IsUnicode(false)");
64036411

6404-
if (!c.IsMaxLength && c.MaxLength > 0 && !doNotSpecifySize)
6412+
if (!c.IsMaxLength && c.MaxLength > 0 && !doNotSpecifySize && !isVectorType) // Vector types use dimension in HasColumnType, not HasMaxLength
64056413
sb.AppendFormat(".HasMaxLength({0})", c.MaxLength);
64066414

64076415
//if (c.IsMaxLength)
@@ -12637,6 +12645,12 @@ and limitations under the License.
1263712645
protected abstract bool HasTemporalTableSupport();
1263812646
public abstract bool HasIdentityColumnSupport();
1263912647

12648+
/// <summary>
12649+
/// Checks if the database supports SQL Server 2025 features (json and vector types).
12650+
/// Returns false by default; overridden in SqlServerDatabaseReader.
12651+
/// </summary>
12652+
public virtual bool HasSqlServer2025TypeSupport() => false;
12653+
1264012654
// Stored proc return objects
1264112655
public abstract void ReadStoredProcReturnObjects(List<StoredProcedure> procs);
1264212656

@@ -13688,6 +13702,12 @@ and limitations under the License.
1368813702
col.SqlPropertyType += "(max)";
1368913703
}
1369013704

13705+
// SQL Server 2025 vector type - include dimension in SqlPropertyType for [Column(TypeName = "vector(n)")]
13706+
if (col.SqlPropertyType.Equals("vector", StringComparison.InvariantCultureIgnoreCase) && col.MaxLength > 0)
13707+
{
13708+
col.SqlPropertyType = $"vector({col.MaxLength})";
13709+
}
13710+
1369113711
if (col.IsPrimaryKey && !col.IsIdentity && col.IsStoreGenerated && rt.TypeName == "uniqueidentifier")
1369213712
{
1369313713
col.IsStoreGenerated = false;
@@ -15490,7 +15510,11 @@ SELECT * FROM MultiContext.ForeignKey;";
1549015510
{ "date", "Date" },
1549115511
{ "time", "Time" },
1549215512
{ "datetime2", "DateTime2" },
15493-
{ "datetimeoffset", "DateTimeOffset" }
15513+
{ "datetimeoffset", "DateTimeOffset" },
15514+
// SQL Server 2025 / Azure SQL types (SqlDbType mappings for stored procedure parameters)
15515+
// Note: C# type mappings (string, SqlVector<float>) are defined in SqlServerToCSharp.cs
15516+
{ "json", "NVarChar" }, // Native JSON type (SQL Server 2025+) -> maps to string in C#
15517+
{ "vector", "VarBinary" } // Native vector type for AI/ML (SQL Server 2025+) -> maps to SqlVector<float> in C#
1549415518
};
1549515519
}
1549615520

@@ -16524,6 +16548,17 @@ OPTION (QUERYTRACEON 9481)";
1652416548
return DatabaseProductMajorVersion >= 13;
1652516549
}
1652616550

16551+
/// <summary>
16552+
/// Checks if the database supports SQL Server 2025 features (json and vector types).
16553+
/// SQL Server 2025 = version 17, or Azure SQL Database with compatibility level 170+.
16554+
/// </summary>
16555+
public override bool HasSqlServer2025TypeSupport()
16556+
{
16557+
// SQL Server 2025 is version 17.x
16558+
// Azure SQL Database also supports these types
16559+
return DatabaseProductMajorVersion >= 17 || IsAzure();
16560+
}
16561+
1652716562
public override bool HasIdentityColumnSupport()
1652816563
{
1652916564
return true;
@@ -17678,7 +17713,6 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
1767817713
public bool EntityClassesArePartial { get; set; }
1767917714
public bool HasHierarchyId { get; set; }
1768017715
public bool HasSpatial { get; set; }
17681-
public bool HasJson { get; set; }
1768217716
public bool HasSqlVector { get; set; }
1768317717
}
1768417718

@@ -19328,7 +19362,7 @@ using {{this}};{{#newline}}
1932819362
if (data.hasStoredProcs)
1932919363
usings.Add("System.Collections.Generic");
1933019364

19331-
if(Settings.OnConfiguration == OnConfiguration.Configuration)
19365+
if (Settings.OnConfiguration == OnConfiguration.Configuration)
1933219366
usings.Add("Microsoft.Extensions.Configuration");
1933319367

1933419368
if (!Settings.UseInheritedBaseInterfaceFunctions)
@@ -20537,15 +20571,11 @@ public class FakeDbContextTransaction : IDbContextTransaction{{#newline}}
2053720571
if (Settings.IncludeCodeGeneratedAttribute)
2053820572
usings.Add("System.CodeDom.Compiler");
2053920573

20540-
if(data.HasHierarchyId)
20574+
if (data.HasHierarchyId)
2054120575
usings.Add("Microsoft.EntityFrameworkCore");
20542-
20543-
if(data.HasJson)
20544-
usings.Add("System.Text.Json");
20545-
20546-
if(data.HasSqlVector)
20547-
usings.Add("Microsoft.Data.SqlClient.Types");
2054820576

20577+
if (data.HasSqlVector)
20578+
usings.Add("Microsoft.Data.SqlClient.Types");
2054920579

2055020580
return usings;
2055120581
}
@@ -20677,7 +20707,7 @@ public class FakeDbContextTransaction : IDbContextTransaction{{#newline}}
2067720707
if (Settings.TrimCharFields)
2067820708
usings.Add("Microsoft.EntityFrameworkCore.Storage.ValueConversion");
2067920709

20680-
if(data.UsesDictionary)
20710+
if (data.UsesDictionary)
2068120711
usings.Add("System.Collections.Generic");
2068220712

2068320713
return usings;
@@ -20905,7 +20935,16 @@ public enum {{EnumName}}{{#newline}}
2090520935

2090620936
public override List<string> PocoUsings(PocoModel data)
2090720937
{
20908-
return CacheList(TemplateFileBasedConstants.Text.PocoUsings);
20938+
var usings = new List<string>(CacheList(TemplateFileBasedConstants.Text.PocoUsings));
20939+
20940+
// Add dynamic namespaces based on column types
20941+
if (data.HasHierarchyId && !usings.Contains("Microsoft.EntityFrameworkCore"))
20942+
usings.Add("Microsoft.EntityFrameworkCore");
20943+
20944+
if (data.HasSqlVector && !usings.Contains("Microsoft.Data.SqlClient.Types"))
20945+
usings.Add("Microsoft.Data.SqlClient.Types");
20946+
20947+
return usings;
2090920948
}
2091020949

2091120950
public override string Poco()

0 commit comments

Comments
 (0)