Skip to content

Commit 0204003

Browse files
committed
Add OdbcGuidTypeMapping because odbc needs gui wrapped in quotes
1 parent 7a9d220 commit 0204003

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Data;
2+
3+
namespace EntityFrameworkCore.Jet.Storage.Internal
4+
{
5+
public class JetOdbcGuidTypeMapping : JetGuidTypeMapping
6+
{
7+
public JetOdbcGuidTypeMapping(string storeType) : base(storeType, System.Data.DbType.Guid)
8+
{
9+
}
10+
11+
protected JetOdbcGuidTypeMapping(RelationalTypeMappingParameters parameters) : base(parameters)
12+
{
13+
}
14+
15+
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters)
16+
=> new JetOdbcGuidTypeMapping(parameters);
17+
18+
/// <summary>
19+
/// Gets the string format to be used to generate SQL literals of this type.
20+
/// </summary>
21+
protected override string SqlLiteralFormatString
22+
=> "'{{{0}}}'";
23+
}
24+
}

src/EFCore.Jet/Storage/Internal/JetTypeMappingSource.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
using EntityFrameworkCore.Jet.Data;
34
using System.Collections;
45
using System.Data;
56
using System.Text.Json;
@@ -49,7 +50,7 @@ public class JetTypeMappingSource : RelationalTypeMappingSource
4950
private readonly JetStringTypeMapping _variableLengthUnicodeString = new("varchar", unicode: true);
5051
private readonly JetStringTypeMapping _variableLengthMaxUnicodeString = new("varchar", unicode: true, size: 255, storeTypePostfix: StoreTypePostfix.Size);
5152
private readonly JetStringTypeMapping _unboundedUnicodeString = new("longchar", unicode: true, storeTypePostfix: StoreTypePostfix.None);
52-
private readonly JetGuidTypeMapping _guid = new("uniqueidentifier", DbType.Guid);
53+
private readonly JetGuidTypeMapping _guid;
5354
private readonly JetByteArrayTypeMapping _rowversion = new("varbinary", size: 8,
5455
comparer: new ValueComparer<byte[]>(
5556
(v1, v2) => StructuralComparisons.StructuralEqualityComparer.Equals(v1, v2),
@@ -78,6 +79,10 @@ public JetTypeMappingSource(
7879
// https://support.office.com/en-us/article/equivalent-ansi-sql-data-types-7a0a6bef-ef25-45f9-8a9a-3c5f21b5c65d
7980
// https://sourcedaddy.com/ms-access/sql-data-types.html
8081

82+
_guid = options.DataAccessProviderType == DataAccessProviderType.Odbc
83+
? new JetOdbcGuidTypeMapping("uniqueidentifier")
84+
: new JetGuidTypeMapping("uniqueidentifier", DbType.Guid);
85+
8186
// TODO: Check the types and their mappings against
8287
// https://docs.microsoft.com/en-us/previous-versions/office/developer/office2000/aa140015(v=office.10)
8388

@@ -87,7 +92,7 @@ public JetTypeMappingSource(
8792
_dateonly = new JetDateOnlyTypeMapping("date", options, dbType: DbType.Date);
8893
_timeonly = new JetTimeOnlyTypeMapping("time", options);
8994
_timespan = new JetTimeSpanTypeMapping("datetime", options);
90-
95+
9196
_storeTypeMappings
9297
= new Dictionary<string, RelationalTypeMapping[]>(StringComparer.OrdinalIgnoreCase)
9398
{

0 commit comments

Comments
 (0)