11// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22
33using System ;
4+ using System . Collections ;
45using System . Collections . Generic ;
56using System . Data ;
67using System . Linq ;
78using EntityFrameworkCore . Jet . Infrastructure . Internal ;
89using EntityFrameworkCore . Jet . Internal ;
910using JetBrains . Annotations ;
11+ using Microsoft . EntityFrameworkCore . ChangeTracking ;
1012using Microsoft . EntityFrameworkCore . Metadata ;
1113using Microsoft . EntityFrameworkCore . Storage ;
1214
@@ -29,7 +31,7 @@ public class JetTypeMappingSource : RelationalTypeMappingSource
2931 // We just map counter etc. to integer. Whether an integer property/column is actually a counter
3032 // is determined by the value generation type.
3133 private readonly IntTypeMapping _counter = new JetIntTypeMapping ( "integer" ) ;
32-
34+
3335 private readonly ByteTypeMapping _byte = new ByteTypeMapping ( "byte" , DbType . Byte ) ; // unsigned, there is no signed byte in Jet
3436 private readonly ShortTypeMapping _smallint = new ShortTypeMapping ( "smallint" , DbType . Int16 ) ;
3537 private readonly IntTypeMapping _integer = new JetIntTypeMapping ( "integer" ) ;
@@ -52,7 +54,11 @@ public class JetTypeMappingSource : RelationalTypeMappingSource
5254 private readonly JetStringTypeMapping _unboundedUnicodeString = new JetStringTypeMapping ( "longchar" , unicode : true , storeTypePostfix : StoreTypePostfix . None ) ;
5355
5456 private readonly GuidTypeMapping _guid = new GuidTypeMapping ( "uniqueidentifier" , DbType . Guid ) ;
55- private readonly JetByteArrayTypeMapping _rowversion = new JetByteArrayTypeMapping ( "varbinary" , size : 8 ) ;
57+ private readonly JetByteArrayTypeMapping _rowversion = new JetByteArrayTypeMapping ( "varbinary" , size : 8 ,
58+ comparer : new ValueComparer < byte [ ] > (
59+ ( v1 , v2 ) => StructuralComparisons . StructuralEqualityComparer . Equals ( v1 , v2 ) ,
60+ v => StructuralComparisons . StructuralEqualityComparer . GetHashCode ( v ) ,
61+ v => v . ToArray ( ) ) ) ;
5662
5763 private readonly Dictionary < string , RelationalTypeMapping > _storeTypeMappings ;
5864 private readonly Dictionary < Type , RelationalTypeMapping > _clrTypeMappings ;
@@ -76,7 +82,7 @@ public JetTypeMappingSource(
7682
7783 // TODO: Check the types and their mappings against
7884 // https://docs.microsoft.com/en-us/previous-versions/office/developer/office2000/aa140015(v=office.10)
79-
85+
8086 _datetime = new JetDateTimeTypeMapping ( "datetime" , options , dbType : DbType . DateTime ) ;
8187 _datetimeoffset = new JetDateTimeOffsetTypeMapping ( "datetime" , options ) ;
8288 _date = new JetDateTimeTypeMapping ( "datetime" , options , dbType : DbType . Date ) ;
@@ -102,11 +108,11 @@ public JetTypeMappingSource(
102108 { "logical" , _bit } ,
103109 { "logical1" , _bit } ,
104110 { "yesno" , _bit } ,
105-
111+
106112 { "counter" , _counter } ,
107113 { "identity" , _counter } ,
108114 { "autoincrement" , _counter } ,
109-
115+
110116 { "byte" , _byte } ,
111117 { "tinyint" , _byte } ,
112118 { "integer1" , _byte } ,
@@ -119,7 +125,7 @@ public JetTypeMappingSource(
119125 { "long" , _bigint } ,
120126 { "int" , _integer } ,
121127 { "integer4" , _integer } ,
122-
128+
123129 { "single" , _single } ,
124130 { "real" , _single } ,
125131 { "float4" , _single } ,
@@ -304,10 +310,10 @@ protected override void ValidateMapping(CoreTypeMapping? mapping, IProperty? pro
304310 const int maxCharColumnSize = 255 ;
305311 const int maxIndexedCharColumnSize = 255 ;
306312
307- var size = mappingInfo . Size ?? ( mappingInfo . IsKeyOrIndex ? ( int ? ) maxIndexedCharColumnSize : null ) ;
313+ var size = mappingInfo . Size ?? ( mappingInfo . IsKeyOrIndex ? ( int ? ) maxIndexedCharColumnSize : null ) ;
308314 if ( size > maxCharColumnSize )
309315 {
310- size = isFixedLength ? maxCharColumnSize : ( int ? ) null ;
316+ size = isFixedLength ? maxCharColumnSize : ( int ? ) null ;
311317 }
312318
313319 return size == null
@@ -331,10 +337,10 @@ protected override void ValidateMapping(CoreTypeMapping? mapping, IProperty? pro
331337
332338 const int maxBinaryColumnSize = 510 ;
333339
334- var size = mappingInfo . Size ?? ( mappingInfo . IsKeyOrIndex ? ( int ? ) maxBinaryColumnSize : null ) ;
340+ var size = mappingInfo . Size ?? ( mappingInfo . IsKeyOrIndex ? ( int ? ) maxBinaryColumnSize : null ) ;
335341 if ( size > maxBinaryColumnSize )
336342 {
337- size = isFixedLength ? maxBinaryColumnSize : ( int ? ) null ;
343+ size = isFixedLength ? maxBinaryColumnSize : ( int ? ) null ;
338344 }
339345
340346 return size == null
0 commit comments