Skip to content

Commit 6512797

Browse files
committed
Improve GetGuid robustness and Guid handling in reader
Refactored GetGuid to handle DBNull, byte[], and string values safely, returning Guid.Empty when configured. Updated GetFieldValue<T> to use GetGuid for Guid types, ensuring consistent and reliable GUID retrieval from the data reader.
1 parent 495765e commit 6512797

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

src/EFCore.Jet.Data/JetDataReader.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,27 @@ public override Guid GetGuid(int ordinal)
314314
{
315315
// Fix for discussion https://jetentityframeworkprovider.codeplex.com/discussions/647028
316316
var value = _wrappedDataReader.GetValue(ordinal);
317-
return JetConfiguration.UseDefaultValueOnDBNullConversionError &&
318-
Convert.IsDBNull(value)
319-
? Guid.Empty
320-
: value is byte[] bytes
321-
? new Guid(bytes)
322-
: (Guid)value;
317+
if (JetConfiguration.UseDefaultValueOnDBNullConversionError &&
318+
Convert.IsDBNull(value))
319+
{
320+
return default;
321+
}
322+
if (value is byte[] bytes)
323+
{
324+
return new Guid(bytes);
325+
}
326+
try
327+
{
328+
return (Guid)value;
329+
}
330+
catch
331+
{
332+
if (value is string s)
333+
{
334+
return new Guid(s);
335+
}
336+
}
337+
return (Guid)value;
323338
}
324339

325340
public override short GetInt16(int ordinal)
@@ -544,6 +559,10 @@ public override T GetFieldValue<T>(int ordinal)
544559
{
545560
return (T)(object)GetDateTimeOffset(ordinal);
546561
}
562+
if (typeof(T) == typeof(Guid))
563+
{
564+
return (T)(object)GetGuid(ordinal);
565+
}
547566

548567
return (T)GetValue(ordinal);
549568
}

0 commit comments

Comments
 (0)