|
385 | 385 | if (column.IsRowVersion) |
386 | 386 | column.Attributes.Add("[Timestamp, ConcurrencyCheck]"); |
387 | 387 |
|
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) |
389 | 395 | { |
390 | 396 | var doNotSpecifySize = (DatabaseType == DatabaseType.SqlCe && column.MaxLength > 4000); |
391 | 397 | column.Attributes.Add(doNotSpecifySize ? "[MaxLength]" : string.Format("[MaxLength({0})]", column.MaxLength)); |
|
3985 | 3991 | BaseClasses = table.BaseClasses, |
3986 | 3992 | InsideClassBody = Settings.WriteInsideClassBody(table), |
3987 | 3993 | HasHierarchyId = table.Columns.Any(x => x.PropertyType.EndsWith("hierarchyid", StringComparison.InvariantCultureIgnoreCase)), |
| 3994 | + HasSqlVector = table.Columns.Any(x => x.PropertyType.StartsWith("SqlVector", StringComparison.InvariantCultureIgnoreCase)), |
3988 | 3995 | Columns = columnsQuery |
3989 | 3996 | .Where(x => !x.Hidden && !x.ExistsInBaseClass) |
3990 | 3997 | .Select((col, index) => new PocoColumnModel |
|
6365 | 6372 | doNotSpecifySize = (DatabaseReader.DoNotSpecifySizeForMaxLength && c.MaxLength > 4000); // Issue #179 |
6366 | 6373 |
|
6367 | 6374 | var excludedHasColumnType = string.Empty; |
| 6375 | + var isVectorType = c.SqlPropertyType != null && c.SqlPropertyType.StartsWith("vector", StringComparison.InvariantCultureIgnoreCase); |
6368 | 6376 | if (!string.IsNullOrEmpty(c.SqlPropertyType)) |
6369 | 6377 | { |
6370 | 6378 | var columnTypeParameters = string.Empty; |
6371 | 6379 |
|
6372 | 6380 | if ((c.Precision > 0 || c.Scale > 0) && (c.SqlPropertyType == "decimal" || c.SqlPropertyType == "numeric")) |
6373 | 6381 | 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 |
6375 | 6383 | columnTypeParameters = $"({c.MaxLength})"; |
6376 | 6384 |
|
6377 | 6385 | if (Column.ExcludedHasColumnType.Contains(c.SqlPropertyType)) |
|
6401 | 6409 | if (!c.IsUnicode) |
6402 | 6410 | sb.Append(".IsUnicode(false)"); |
6403 | 6411 |
|
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 |
6405 | 6413 | sb.AppendFormat(".HasMaxLength({0})", c.MaxLength); |
6406 | 6414 |
|
6407 | 6415 | //if (c.IsMaxLength) |
@@ -12637,6 +12645,12 @@ and limitations under the License. |
12637 | 12645 | protected abstract bool HasTemporalTableSupport(); |
12638 | 12646 | public abstract bool HasIdentityColumnSupport(); |
12639 | 12647 |
|
| 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 | + |
12640 | 12654 | // Stored proc return objects |
12641 | 12655 | public abstract void ReadStoredProcReturnObjects(List<StoredProcedure> procs); |
12642 | 12656 |
|
@@ -13688,6 +13702,12 @@ and limitations under the License. |
13688 | 13702 | col.SqlPropertyType += "(max)"; |
13689 | 13703 | } |
13690 | 13704 |
|
| 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 | + |
13691 | 13711 | if (col.IsPrimaryKey && !col.IsIdentity && col.IsStoreGenerated && rt.TypeName == "uniqueidentifier") |
13692 | 13712 | { |
13693 | 13713 | col.IsStoreGenerated = false; |
@@ -15490,7 +15510,11 @@ SELECT * FROM MultiContext.ForeignKey;"; |
15490 | 15510 | { "date", "Date" }, |
15491 | 15511 | { "time", "Time" }, |
15492 | 15512 | { "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# |
15494 | 15518 | }; |
15495 | 15519 | } |
15496 | 15520 |
|
@@ -16524,6 +16548,17 @@ OPTION (QUERYTRACEON 9481)"; |
16524 | 16548 | return DatabaseProductMajorVersion >= 13; |
16525 | 16549 | } |
16526 | 16550 |
|
| 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 | + |
16527 | 16562 | public override bool HasIdentityColumnSupport() |
16528 | 16563 | { |
16529 | 16564 | return true; |
@@ -17678,7 +17713,6 @@ SELECT SERVERPROPERTY('Edition') AS Edition, |
17678 | 17713 | public bool EntityClassesArePartial { get; set; } |
17679 | 17714 | public bool HasHierarchyId { get; set; } |
17680 | 17715 | public bool HasSpatial { get; set; } |
17681 | | - public bool HasJson { get; set; } |
17682 | 17716 | public bool HasSqlVector { get; set; } |
17683 | 17717 | } |
17684 | 17718 |
|
@@ -19328,7 +19362,7 @@ using {{this}};{{#newline}} |
19328 | 19362 | if (data.hasStoredProcs) |
19329 | 19363 | usings.Add("System.Collections.Generic"); |
19330 | 19364 |
|
19331 | | - if(Settings.OnConfiguration == OnConfiguration.Configuration) |
| 19365 | + if (Settings.OnConfiguration == OnConfiguration.Configuration) |
19332 | 19366 | usings.Add("Microsoft.Extensions.Configuration"); |
19333 | 19367 |
|
19334 | 19368 | if (!Settings.UseInheritedBaseInterfaceFunctions) |
@@ -20537,15 +20571,11 @@ public class FakeDbContextTransaction : IDbContextTransaction{{#newline}} |
20537 | 20571 | if (Settings.IncludeCodeGeneratedAttribute) |
20538 | 20572 | usings.Add("System.CodeDom.Compiler"); |
20539 | 20573 |
|
20540 | | - if(data.HasHierarchyId) |
| 20574 | + if (data.HasHierarchyId) |
20541 | 20575 | 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"); |
20548 | 20576 |
|
| 20577 | + if (data.HasSqlVector) |
| 20578 | + usings.Add("Microsoft.Data.SqlClient.Types"); |
20549 | 20579 |
|
20550 | 20580 | return usings; |
20551 | 20581 | } |
@@ -20677,7 +20707,7 @@ public class FakeDbContextTransaction : IDbContextTransaction{{#newline}} |
20677 | 20707 | if (Settings.TrimCharFields) |
20678 | 20708 | usings.Add("Microsoft.EntityFrameworkCore.Storage.ValueConversion"); |
20679 | 20709 |
|
20680 | | - if(data.UsesDictionary) |
| 20710 | + if (data.UsesDictionary) |
20681 | 20711 | usings.Add("System.Collections.Generic"); |
20682 | 20712 |
|
20683 | 20713 | return usings; |
@@ -20905,7 +20935,16 @@ public enum {{EnumName}}{{#newline}} |
20905 | 20935 |
|
20906 | 20936 | public override List<string> PocoUsings(PocoModel data) |
20907 | 20937 | { |
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; |
20909 | 20948 | } |
20910 | 20949 |
|
20911 | 20950 | public override string Poco() |
|
0 commit comments