I've update the example. The output I get is:
Code: Select all
Culture: English (United States)
Timezone: (UTC-08:00) Pacific Time (US & Canada)
Dll Version: Devart.Data.dll, v5.0.1075.0
Dll Version: Devart.Data.PostgreSql.dll, v7.3.283.0
Dll Version: Devart.Data.PostgreSql.Entity.dll, v7.3.283.6
Pg Version: PostgreSQL 9.2.1, compiled by Visual C++ build 1600, 64-bit
Pg Timezone: UTC
INSERT INTO "data"("date")
VALUES (:p0)
RETURNING id
SELECT
"Extent1".id,
CAST("Extent1"."date" AS timestamptz) AS "C1"
FROM "data" AS "Extent1"
The UTC Offset of the local dateTime parameter does not match the offset argumen
t.
Parameter name: offset
at System.DateTimeOffset..ctor(DateTime dateTime, TimeSpan offset)
at Devart.Data.PostgreSql.f.bc(Byte[] A_0, Int32 A_1, Int32 A_2)
at Devart.Data.PostgreSql.PgSqlDataReader.GetDateTimeOffset(Int32 i)
at Devart.Data.PostgreSql.Entity.ae.a(Int32 A_0)
at Devart.Common.Entity.au.GetValue(Int32 ordinal)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandli
ngValueReader`1.GetUntypedValueDefault(DbDataReader reader, Int32 ordinal)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandli
ngValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetColumnVa
lueWithErrorHandling[TColumn](Int32 ordinal)
at lambda_method(Closure , Shaper )
at System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.Read
NextElement(Shaper shaper)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.SimpleEnu
merator.MoveNext()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at DevartBugTester.Program.<>c__DisplayClass2.<Main>b__1(DateTime date) in c:
\Users\Administrator\Desktop\DevartBugTester\Program.cs:line 127
Updated test case:
Code: Select all
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Data.Common;
using System.Data.Entity;
using System.Globalization;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Infrastructure.Interception;
using Devart.Common;
using Devart.Data.PostgreSql;
using Devart.Data.PostgreSql.Entity.Migrations;
namespace DevartBugTester
{
// Setup a new DB and execute the following:
// create table data
// (
// id serial,
// date timestamp without time zone,
// constraint pk_data primary key (id)
// )
public class Data
{
public int Id { get; set; }
public DateTime Date { get; set; }
public const string Table = "data";
}
public class Projection
{
public int id { get; set; }
public DateTimeOffset date { get; set; }
}
public class Store : DbContext
{
public Store(string nameOrConnectionString)
: base(nameOrConnectionString)
{
Database.SetInitializer<Store>(null);
}
public IDbSet<Data> Data { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder
.Entity<Data>()
.ToTable(DevartBugTester.Data.Table)
.HasKey(x => x.Id)
.Property(x => x.Id)
.HasColumnName("id")
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<Data>().Property(x => x.Date).HasColumnName("date");
}
}
public class StoreConfiguration : DbConfiguration
{
class CommandInterceptor : IDbCommandInterceptor
{
public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
}
public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
}
public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
}
public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
Console.WriteLine();
Console.WriteLine(command.CommandText);
}
public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
}
public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
}
}
public StoreConfiguration()
{
AddInterceptor(new CommandInterceptor());
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Culture:\t" + CultureInfo.CurrentCulture.DisplayName);
Console.WriteLine("Timezone:\t" + TimeZoneInfo.Local.DisplayName);
LogAssmVersion(typeof(DbCommandBase));
LogAssmVersion(typeof(PgSqlConnection));
LogAssmVersion(typeof(PgSqlConnectionInfo));
var name = "Bug";
var store = new Store(name);
store.Database.Connection.Open();
LogPgInfo(store, "Version", "select version()");
LogPgInfo(store, "Timezone", "select current_setting('TIMEZONE') tz");
Action<DateTime> testDate = date =>
{
try
{
store.Data.Add(new Data { Date = date });
store.SaveChanges();
var data = store.Data.Select(x => new Projection
{
date = x.Date,
id = x.Id
})
.ToArray();
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
finally
{
store.Database.ExecuteSqlCommand("delete from data");
}
};
// Causes - "The UTC Offset of the local dateTime parameter does not match the offset argument."
testDate(new DateTime(1971, 11, 2));
}
static void LogAssmVersion(Type type)
{
var info = new FileInfo(type.Assembly.Location);
Console.WriteLine(
"Dll Version:\t{0}, v{1}",
info.Name,
type.Assembly.GetName().Version.ToString());
}
static void LogPgInfo(Store store, string label, string command)
{
using (var cmd = store.Database.Connection.CreateCommand())
{
cmd.CommandText = command;
Console.WriteLine("Pg {0}:\t{1}", label, cmd.ExecuteScalar());
}
}
}
}