Skip to content

Commit 4ef5f4b

Browse files
committed
Fix for issue ThatRendle#249
1 parent d791b71 commit 4ef5f4b

4 files changed

Lines changed: 27 additions & 3 deletions

File tree

Simple.Data.Ado/TypeHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static class TypeHelper
2323
typeof (double),
2424
typeof (decimal),
2525
typeof (DateTime),
26+
typeof (DateTimeOffset),
2627
typeof (string),
2728
typeof (byte[]),
2829
typeof (Guid),
@@ -49,14 +50,14 @@ public static class TypeHelper
4950
{DbType.StringFixedLength, typeof(string)},
5051
{DbType.AnsiStringFixedLength, typeof(string)},
5152
{DbType.Xml, typeof(string)},
52-
{DbType.DateTimeOffset, typeof(DateTime)},
5353
{DbType.DateTime2, typeof(DateTime)},
5454
{DbType.VarNumeric, typeof(double)},
5555
{DbType.UInt16, typeof(ushort)},
5656
{DbType.String, typeof(string)},
5757
{DbType.Time, typeof(TimeSpan)},
5858
{DbType.UInt64, typeof(ulong)},
59-
{DbType.UInt32, typeof(uint)}
59+
{DbType.UInt32, typeof(uint)},
60+
{DbType.DateTimeOffset, typeof(DateTimeOffset)},
6061
};
6162

6263
public static bool IsKnownType(Type type)

Simple.Data.SqlServer/SqlTypeResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static class SqlTypeResolver
1616
{"date", typeof (DateTime)},
1717
{"time", typeof (DateTime)},
1818
{"datetime2", typeof (DateTime)},
19-
{"datetimeoffset", typeof (DateTime)},
19+
{"datetimeoffset", typeof (DateTimeOffset)},
2020
{"tinyint", typeof (byte)},
2121
{"smallint", typeof (short)},
2222
{"int", typeof (int)},

Simple.Data.SqlTest/InsertTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Simple.Data.SqlTest
99
{
10+
using System;
11+
1012
[TestFixture]
1113
public class InsertTests
1214
{
@@ -293,5 +295,16 @@ public void TestInsertWithTimestampColumn()
293295
Assert.IsNotNull(row);
294296
Assert.IsInstanceOf<byte[]>(row.Version);
295297
}
298+
299+
[Test]
300+
public void TestInsertWithDateTimeOffsetColumn()
301+
{
302+
var db = DatabaseHelper.Open();
303+
dynamic entry = new ExpandoObject();
304+
var time = DateTimeOffset.Now;
305+
entry.time = time;
306+
var inserted = db.DateTimeOffsetTest.Insert(entry);
307+
Assert.AreEqual(time, inserted.time);
308+
}
296309
}
297310
}

Simple.Data.SqlTest/Resources/DatabaseReset.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ BEGIN
7070
DROP TABLE [dbo].[Blobs]
7171
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EnumTest]') AND type in (N'U'))
7272
DROP TABLE [dbo].[EnumTest]
73+
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DateTimeOffsetTest]') AND type in (N'U'))
74+
DROP TABLE [dbo].[DateTimeOffsetTest]
7375
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DeleteTest]') AND type in (N'U'))
7476
DROP TABLE [dbo].[DeleteTest]
7577
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DecimalTest]') AND type in (N'U'))
@@ -190,6 +192,14 @@ BEGIN
190192
ALTER TABLE [dbo].[DeleteTest]
191193
ADD CONSTRAINT [PK_DeleteTest] PRIMARY KEY CLUSTERED ([Id] ASC)
192194

195+
CREATE TABLE [dbo].[DateTimeOffsetTest](
196+
[Id] [int] IDENTITY(1,1) NOT NULL,
197+
[Time] [datetimeoffset]
198+
)
199+
200+
ALTER TABLE [dbo].[DateTimeOffsetTest]
201+
ADD CONSTRAINT [PK_DateTimeOffsetTest] PRIMARY KEY CLUSTERED ([Id] ASC)
202+
193203
CREATE TABLE [dbo].[DecimalTest](
194204
[Id] [int] IDENTITY (1, 1) NOT NULL,
195205
[Value] [decimal](20,6) NOT NULL

0 commit comments

Comments
 (0)