diff --git a/Dapper.StrongName/Dapper.StrongName.csproj b/Dapper.StrongName/Dapper.StrongName.csproj
index 023a4eae4..ae4460f62 100644
--- a/Dapper.StrongName/Dapper.StrongName.csproj
+++ b/Dapper.StrongName/Dapper.StrongName.csproj
@@ -5,7 +5,7 @@
Dapper (Strong Named)
A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..
Sam Saffron;Marc Gravell;Nick Craver
- net461;netstandard2.0;net5.0
+ net461;netstandard2.0;net5.0;net6.0
true
true
@@ -14,8 +14,7 @@
-
- $(DefineConstants);PLAT_NO_REMOTING;PLAT_SKIP_LOCALS_INIT
+
true
diff --git a/Dapper/Dapper.csproj b/Dapper/Dapper.csproj
index 25f87ccf6..086386a6e 100644
--- a/Dapper/Dapper.csproj
+++ b/Dapper/Dapper.csproj
@@ -5,14 +5,13 @@
orm;sql;micro-orm
A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..
Sam Saffron;Marc Gravell;Nick Craver
- net461;netstandard2.0;net5.0
+ net461;netstandard2.0;net5.0;net6.0
-
- $(DefineConstants);PLAT_NO_REMOTING;PLAT_SKIP_LOCALS_INIT
+
true
diff --git a/Dapper/Properties/AssemblyInfo.cs b/Dapper/Properties/AssemblyInfo.cs
index d6c9623b5..f1bead0aa 100644
--- a/Dapper/Properties/AssemblyInfo.cs
+++ b/Dapper/Properties/AssemblyInfo.cs
@@ -1,4 +1,4 @@
-#if PLAT_SKIP_LOCALS_INIT
+#if NET5_0_OR_GREATER
[module: System.Runtime.CompilerServices.SkipLocalsInit]
#endif
diff --git a/Dapper/SqlMapper.cs b/Dapper/SqlMapper.cs
index ee49c2abd..2b3c70290 100644
--- a/Dapper/SqlMapper.cs
+++ b/Dapper/SqlMapper.cs
@@ -187,6 +187,10 @@ static SqlMapper()
[typeof(DateTime)] = null,
[typeof(DateTimeOffset)] = DbType.DateTimeOffset,
[typeof(TimeSpan)] = null,
+#if NET6_0_OR_GREATER
+ [typeof(DateOnly)] = null,
+ [typeof(TimeOnly)] = null,
+#endif
[typeof(byte[])] = DbType.Binary,
[typeof(byte?)] = DbType.Byte,
[typeof(sbyte?)] = DbType.SByte,
@@ -205,6 +209,10 @@ static SqlMapper()
[typeof(DateTime?)] = null,
[typeof(DateTimeOffset?)] = DbType.DateTimeOffset,
[typeof(TimeSpan?)] = null,
+#if NET6_0_OR_GREATER
+ [typeof(DateOnly?)] = null,
+ [typeof(TimeOnly?)] = null,
+#endif
[typeof(object)] = DbType.Object
};
ResetTypeHandlers(false);
diff --git a/Dapper/WrappedReader.cs b/Dapper/WrappedReader.cs
index f092823f5..0bfd01ed9 100644
--- a/Dapper/WrappedReader.cs
+++ b/Dapper/WrappedReader.cs
@@ -32,7 +32,7 @@ private async static Task ThrowDisposedAsync()
public override void Close() { }
public override DataTable GetSchemaTable() => ThrowDisposed();
-#if PLAT_NO_REMOTING
+#if NET5_0_OR_GREATER
[Obsolete("This Remoting API is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0010", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public override object InitializeLifetimeService() => ThrowDisposed
diff --git a/tests/Dapper.Tests/ParameterTests.cs b/tests/Dapper.Tests/ParameterTests.cs
index 7179563ad..63980268d 100644
--- a/tests/Dapper.Tests/ParameterTests.cs
+++ b/tests/Dapper.Tests/ParameterTests.cs
@@ -1593,5 +1593,27 @@ private static int GetExpectedListExpansionCount(int count, bool enabled)
if (delta != 0) blocks++;
return blocks * padFactor;
}
+
+#if NET6_0_OR_GREATER
+ [Fact]
+ public void TestDateOnlyTimeOnly()
+ {
+
+ var now = DateTime.UtcNow;
+ var args = new { day = DateOnly.FromDateTime(now), time = TimeOnly.FromDateTime(now) };
+ try
+ {
+ var (day, time) = connection.QuerySingle<(DateOnly, TimeOnly)>("select @day, @time", args);
+
+ Assert.Equal(args.day, day);
+ Assert.Equal(args.time, time);
+ }
+ catch (ArgumentException ex) when(ex.StackTrace.Contains("MetaType.GetMetaTypeFromValue"))
+ {
+ Skip.Inconclusive("Feature not supported by provider");
+ }
+ }
+
+#endif
}
}
diff --git a/tests/Dapper.Tests/Providers/PostgresqlTests.cs b/tests/Dapper.Tests/Providers/PostgresqlTests.cs
index bc90f1721..9a1b56262 100644
--- a/tests/Dapper.Tests/Providers/PostgresqlTests.cs
+++ b/tests/Dapper.Tests/Providers/PostgresqlTests.cs
@@ -141,5 +141,25 @@ static FactPostgresqlAttribute()
}
}
}
+
+#if NET6_0_OR_GREATER
+ [Fact]
+ public void TestDateOnlyTimeOnly()
+ {
+
+ var now = DateTime.UtcNow;
+ var args = new { day = DateOnly.FromDateTime(now), time = TimeOnly.FromDateTime(now) };
+ var result = connection.QuerySingle("select @day::date as day, @time::time as time", args);
+
+ var day = DateOnly.FromDateTime(Assert.IsType(result.day));
+ var time = TimeOnly.FromTimeSpan(Assert.IsType(result.time));
+
+ Assert.Equal(args.day, day);
+ Assert.Equal(Round(args.time), Round(time));
+
+ static TimeOnly Round(TimeOnly value)
+ => new TimeOnly(value.Hour, value.Minute, value.Second);
+ }
+#endif
}
}
diff --git a/tests/Dapper.Tests/Providers/SqliteTests.cs b/tests/Dapper.Tests/Providers/SqliteTests.cs
index a5aeb086f..0473c70dd 100644
--- a/tests/Dapper.Tests/Providers/SqliteTests.cs
+++ b/tests/Dapper.Tests/Providers/SqliteTests.cs
@@ -160,6 +160,23 @@ public void DateTimeIsParsedWithInvariantCulture()
}
}
+#if NET6_0_OR_GREATER
+ [Fact]
+ public void TestDateOnlyTimeOnly()
+ {
+
+ var now = DateTime.UtcNow;
+ var args = new { day = DateOnly.FromDateTime(now), time = TimeOnly.FromDateTime(now) };
+ var result = connection.QuerySingle("select @day as day, @time as time", args);
+
+ var day = DateOnly.Parse(Assert.IsType(result.day));
+ var time = TimeOnly.Parse(Assert.IsType(result.time));
+
+ Assert.Equal(args.day, day);
+ Assert.Equal(args.time, time);
+ }
+#endif
+
private class PersonWithDob
{
public int Id { get; set; }
diff --git a/tests/Dapper.Tests/TestBase.cs b/tests/Dapper.Tests/TestBase.cs
index afc9a0f47..1c771424a 100644
--- a/tests/Dapper.Tests/TestBase.cs
+++ b/tests/Dapper.Tests/TestBase.cs
@@ -50,7 +50,7 @@ public DbParameter CreateRawParameter(string name, object value)
public abstract class SqlServerDatabaseProvider : DatabaseProvider
{
public override string GetConnectionString() =>
- GetConnectionString("SqlServerConnectionString", "Data Source=.;Initial Catalog=tempdb;Integrated Security=True");
+ GetConnectionString("SqlServerConnectionString", "Data Source=.;Initial Catalog=tempdb;Integrated Security=True;TrustServerCertificate=True");
public DbConnection GetOpenConnection(bool mars)
{