Skip to content

Commit e3006fc

Browse files
Fixed value conversion issue with ado.net context
1 parent ec82ce8 commit e3006fc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/DotNetToolkit.Repository.AdoNet/Internal/DbDataReaderExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ internal static class DbDataReaderExtensions
77
{
88
public static T GetValue<T>(this DbDataReader reader, int ordinal)
99
{
10+
var t = typeof(T);
1011
var value = reader.GetValue(ordinal);
1112

1213
if (value == null || value == DBNull.Value)
1314
{
1415
return default(T);
1516
}
16-
else
17+
else if (t.IsGenericType && t.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
1718
{
18-
return (T)value;
19+
t = Nullable.GetUnderlyingType(t);
1920
}
21+
22+
return (T)Convert.ChangeType(value, t);
2023
}
2124
}
2225
}

0 commit comments

Comments
 (0)