Skip to content

Commit

Permalink
Improve EFTableRowsDataReader
Browse files Browse the repository at this point in the history
  • Loading branch information
VahidN committed Mar 30, 2020
1 parent 9e41b24 commit 89324c6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Entity Framework Core Second Level Caching Library.</Description>
<VersionPrefix>1.3.1</VersionPrefix>
<VersionPrefix>1.3.2</VersionPrefix>
<Authors>Vahid Nasiri</Authors>
<TargetFrameworks>netstandard2.0;net461;</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard2.0</TargetFrameworks>
Expand Down
36 changes: 30 additions & 6 deletions src/EFCoreSecondLevelCacheInterceptor/EFTableRowsDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,17 @@ public override bool Read()
public override bool GetBoolean(int ordinal)
{
var value = GetValue(ordinal);
if (value.GetType() == typeof(long))
var valueType = value.GetType();
if (valueType == typeof(long))
{
return (long)value != 0;
}

if (valueType == typeof(ulong))
{
return (ulong)value != 0;
}

return (bool)value;
}

Expand Down Expand Up @@ -190,9 +196,9 @@ public override char GetChar(int ordinal)
public override DateTime GetDateTime(int ordinal)
{
var value = GetValue(ordinal);
if (value.GetType() == typeof(string))
if (value.GetType() != typeof(DateTime))
{
return DateTime.Parse(value.ToString(), CultureInfo.InvariantCulture);
return DateTime.Parse(value.ToString());
}

return (DateTime)value;
Expand Down Expand Up @@ -234,11 +240,17 @@ public override decimal GetDecimal(int ordinal)
public override float GetFloat(int ordinal)
{
var value = GetValue(ordinal);
if (value.GetType() == typeof(double))
var valueType = value.GetType();
if (valueType == typeof(double))
{
return (float)(double)value;
}

if (valueType != typeof(float))
{
return (float)Convert.ChangeType(value, typeof(float));
}

return (float)value;
}

Expand All @@ -262,11 +274,17 @@ public override Guid GetGuid(int ordinal)
public override short GetInt16(int ordinal)
{
var value = GetValue(ordinal);
if (value.GetType() == typeof(long))
var valueType = value.GetType();
if (valueType == typeof(long))
{
return (short)(long)value;
}

if (valueType != typeof(short))
{
return (short)Convert.ChangeType(value, typeof(short));
}

return (short)value;
}

Expand All @@ -276,11 +294,17 @@ public override short GetInt16(int ordinal)
public override int GetInt32(int ordinal)
{
var value = GetValue(ordinal);
if (value.GetType() == typeof(long))
var valueType = value.GetType();
if (valueType == typeof(long))
{
return (int)(long)value;
}

if (valueType != typeof(int))
{
return (int)Convert.ChangeType(value, typeof(int));
}

return (int)value;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Issues/Issue12MySQL/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"ApplicationDbContextConnection": "server=localhost;port=3306;user=root;password=MySql-1399#1;database=Issue12MySQL;TreatTinyAsBoolean=true"
"ApplicationDbContextConnection": "server=localhost;port=3306;user=root;password=MySql-1399#1;database=Issue12MySQL;TreatTinyAsBoolean=true;AllowZeroDateTime=true;ConvertZeroDateTime=true;"
},
"RedisConfiguration": "localhost:6379"
}
2 changes: 1 addition & 1 deletion tag-it.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
git tag -a 1.3.1 -m "Published 1.3.1 to nuget.org"
git tag -a 1.3.2 -m "Published 1.3.2 to nuget.org"
git push --follow-tags
pause

0 comments on commit 89324c6

Please sign in to comment.