|
105 | 105 | public static List<string> AdditionalFileHeaderText = new List<string>(); // This will put additional lines verbatim at the top of each file under the comments, 1 line per entry |
106 | 106 | public static List<string> AdditionalFileFooterText = new List<string>(); // This will put additional lines verbatim at the end of each file above the // </auto-generated>, 1 line per entry |
107 | 107 | public static OrderProperties OrderProperties = OrderProperties.Ordinal; // Order the properties in the generated POCO classes. Ordinal, Alphabetical |
108 | | - public static bool AutoMapSqlServer2025Types = true; // If true, allows custom mapping of SQL Server 2025/Azure SQL vector and json types via UpdateColumn delegate (EFCore 10+ only) |
109 | 108 |
|
110 | 109 | // Language choices |
111 | 110 | public static GenerationLanguage GenerationLanguage = GenerationLanguage.CSharp; |
|
3991 | 3990 | BaseClasses = table.BaseClasses, |
3992 | 3991 | InsideClassBody = Settings.WriteInsideClassBody(table), |
3993 | 3992 | HasHierarchyId = table.Columns.Any(x => x.PropertyType.EndsWith("hierarchyid", StringComparison.InvariantCultureIgnoreCase)), |
3994 | | - HasSqlVector = table.Columns.Any(x => x.PropertyType.StartsWith("SqlVector", StringComparison.InvariantCultureIgnoreCase)), |
| 3993 | + HasSqlVector = table.Columns.Any(x => x.PropertyType.StartsWith("SqlVector", StringComparison.InvariantCultureIgnoreCase)) && Settings.IsEfCore10Plus(), |
3995 | 3994 | Columns = columnsQuery |
3996 | 3995 | .Where(x => !x.Hidden && !x.ExistsInBaseClass) |
3997 | 3996 | .Select((col, index) => new PocoColumnModel |
|
7556 | 7555 | var geographyType = isEf6 ? "DbGeography" : "NetTopologySuite.Geometries.Point"; |
7557 | 7556 | var geometryType = isEf6 ? "DbGeometry" : "NetTopologySuite.Geometries.Geometry"; |
7558 | 7557 |
|
| 7558 | + // SQL Server 2025 / Azure SQL vector type: |
| 7559 | + // - EF Core 10+: SqlVector<float> (native support, requires Microsoft.Data.SqlTypes namespace) |
| 7560 | + // - EF6/EFCore8/EFCore9: byte[] (fallback - no native support, stored as varbinary internally) |
| 7561 | + var vectorType = Settings.IsEfCore10Plus() ? "SqlVector<float>" : "byte[]"; |
| 7562 | + |
7559 | 7563 | return new Dictionary<string, string> |
7560 | 7564 | { |
7561 | 7565 | { string.Empty, "string" }, // default |
|
7573 | 7577 | { "hierarchyid", "Hierarchy.HierarchyId" }, |
7574 | 7578 | { "image", "byte[]" }, |
7575 | 7579 | { "int", "int" }, |
7576 | | - { "json", "string" }, // SQL Server 2025 / Azure SQL native json type |
| 7580 | + { "json", "string" }, // SQL Server 2025 / Azure SQL native json type (string works for all EF versions) |
7577 | 7581 | { "money", "decimal" }, |
7578 | 7582 | { "numeric", "decimal" }, |
7579 | 7583 | { "real", "float" }, |
|
7585 | 7589 | { "timestamp", "byte[]" }, |
7586 | 7590 | { "tinyint", "byte" }, |
7587 | 7591 | { "uniqueidentifier", "Guid" }, |
7588 | | - { "vector", "SqlVector<float>" }, // SQL Server 2025 / Azure SQL vector type for AI/ML (requires Microsoft.Data.SqlClient.Types namespace) |
| 7592 | + { "vector", vectorType }, |
7589 | 7593 | { "varbinary", "byte[]" }, |
7590 | 7594 | { "varbinary(max)", "byte[]" } |
7591 | 7595 | }; |
@@ -13705,9 +13709,12 @@ and limitations under the License. |
13705 | 13709 | } |
13706 | 13710 |
|
13707 | 13711 | // SQL Server 2025 vector type - include dimension in SqlPropertyType for [Column(TypeName = "vector(n)")] |
| 13712 | + // CHARACTER_MAXIMUM_LENGTH returns byte size, not dimension. Each float = 4 bytes, plus 8 bytes overhead. |
| 13713 | + // Formula: dimension = (byte_size - 8) / 4 |
13708 | 13714 | if (col.SqlPropertyType.Equals("vector", StringComparison.InvariantCultureIgnoreCase) && col.MaxLength > 0) |
13709 | 13715 | { |
13710 | | - col.SqlPropertyType = $"vector({col.MaxLength})"; |
| 13716 | + var vectorDimension = (col.MaxLength - 8) / 4; |
| 13717 | + col.SqlPropertyType = $"vector({vectorDimension})"; |
13711 | 13718 | } |
13712 | 13719 |
|
13713 | 13720 | if (col.IsPrimaryKey && !col.IsIdentity && col.IsStoreGenerated && rt.TypeName == "uniqueidentifier") |
@@ -20578,7 +20585,7 @@ public class FakeDbContextTransaction : IDbContextTransaction{{#newline}} |
20578 | 20585 | usings.Add("Microsoft.EntityFrameworkCore"); |
20579 | 20586 |
|
20580 | 20587 | if (data.HasSqlVector) |
20581 | | - usings.Add("Microsoft.Data.SqlClient.Types"); |
| 20588 | + usings.Add("Microsoft.Data.SqlTypes"); |
20582 | 20589 |
|
20583 | 20590 | return usings; |
20584 | 20591 | } |
@@ -20944,8 +20951,8 @@ public enum {{EnumName}}{{#newline}} |
20944 | 20951 | if (data.HasHierarchyId && !usings.Contains("Microsoft.EntityFrameworkCore")) |
20945 | 20952 | usings.Add("Microsoft.EntityFrameworkCore"); |
20946 | 20953 |
|
20947 | | - if (data.HasSqlVector && !usings.Contains("Microsoft.Data.SqlClient.Types")) |
20948 | | - usings.Add("Microsoft.Data.SqlClient.Types"); |
| 20954 | + if (data.HasSqlVector && !usings.Contains("Microsoft.Data.SqlTypes")) |
| 20955 | + usings.Add("Microsoft.Data.SqlTypes"); |
20949 | 20956 |
|
20950 | 20957 | return usings; |
20951 | 20958 | } |
|
0 commit comments