Permalink
Browse files

Fix for issue #249

  • Loading branch information...
1 parent d791b71 commit 4ef5f4bb4ede5f68b0a98742938a3648068a4990 @markrendle committed Dec 3, 2012
@@ -23,6 +23,7 @@ public static class TypeHelper
typeof (double),
typeof (decimal),
typeof (DateTime),
+ typeof (DateTimeOffset),
typeof (string),
typeof (byte[]),
typeof (Guid),
@@ -49,14 +50,14 @@ public static class TypeHelper
{DbType.StringFixedLength, typeof(string)},
{DbType.AnsiStringFixedLength, typeof(string)},
{DbType.Xml, typeof(string)},
- {DbType.DateTimeOffset, typeof(DateTime)},
{DbType.DateTime2, typeof(DateTime)},
{DbType.VarNumeric, typeof(double)},
{DbType.UInt16, typeof(ushort)},
{DbType.String, typeof(string)},
{DbType.Time, typeof(TimeSpan)},
{DbType.UInt64, typeof(ulong)},
- {DbType.UInt32, typeof(uint)}
+ {DbType.UInt32, typeof(uint)},
+ {DbType.DateTimeOffset, typeof(DateTimeOffset)},
};
public static bool IsKnownType(Type type)
@@ -16,7 +16,7 @@ static class SqlTypeResolver
{"date", typeof (DateTime)},
{"time", typeof (DateTime)},
{"datetime2", typeof (DateTime)},
- {"datetimeoffset", typeof (DateTime)},
+ {"datetimeoffset", typeof (DateTimeOffset)},
{"tinyint", typeof (byte)},
{"smallint", typeof (short)},
{"int", typeof (int)},
@@ -7,6 +7,8 @@
namespace Simple.Data.SqlTest
{
+ using System;
+
[TestFixture]
public class InsertTests
{
@@ -293,5 +295,16 @@ public void TestInsertWithTimestampColumn()
Assert.IsNotNull(row);
Assert.IsInstanceOf<byte[]>(row.Version);
}
+
+ [Test]
+ public void TestInsertWithDateTimeOffsetColumn()
+ {
+ var db = DatabaseHelper.Open();
+ dynamic entry = new ExpandoObject();
+ var time = DateTimeOffset.Now;
+ entry.time = time;
+ var inserted = db.DateTimeOffsetTest.Insert(entry);
+ Assert.AreEqual(time, inserted.time);
+ }
}
}
@@ -70,6 +70,8 @@ BEGIN
DROP TABLE [dbo].[Blobs]
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EnumTest]') AND type in (N'U'))
DROP TABLE [dbo].[EnumTest]
+ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DateTimeOffsetTest]') AND type in (N'U'))
+ DROP TABLE [dbo].[DateTimeOffsetTest]
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DeleteTest]') AND type in (N'U'))
DROP TABLE [dbo].[DeleteTest]
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DecimalTest]') AND type in (N'U'))
@@ -190,6 +192,14 @@ BEGIN
ALTER TABLE [dbo].[DeleteTest]
ADD CONSTRAINT [PK_DeleteTest] PRIMARY KEY CLUSTERED ([Id] ASC)
+ CREATE TABLE [dbo].[DateTimeOffsetTest](
+ [Id] [int] IDENTITY(1,1) NOT NULL,
+ [Time] [datetimeoffset]
+ )
+
+ ALTER TABLE [dbo].[DateTimeOffsetTest]
+ ADD CONSTRAINT [PK_DateTimeOffsetTest] PRIMARY KEY CLUSTERED ([Id] ASC)
+
CREATE TABLE [dbo].[DecimalTest](
[Id] [int] IDENTITY (1, 1) NOT NULL,
[Value] [decimal](20,6) NOT NULL

0 comments on commit 4ef5f4b

Please sign in to comment.