My test date is:
Code: Select all
2018-10-28 02:40 +02:00
After posting to the database, postgres gets the entry:
Code: Select all
2018-10-28 01:40:00 +02:00
I would expect the driver to write to the database what has been forwarded.
Please indicate how to do it or fix the error.
I'm attaching a program that can reproduce the error. Currently, this is a mistake with a high status for me, because at the time of the change of time, the dates recorded at the moment of time change are saved incorrectly.<br/>
I would like to mention that I tried to use:
Code: Select all
PgSqlLocalization.TimeZone = "+0";
Code: Select all
2018-10-28 02:40 +02:00
program to reproduce issue:
Code: Select all
using Devart.Common;
using Devart.Data.PostgreSql;
using Devart.Data.PostgreSql.Entity.Migrations;
using System;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure.Interception;
using System.Globalization;
using System.IO;
namespace OffsetDTSIssue
{
public class Table
{
public int Id { get; set; }
public DateTimeOffset Date { get; set; }
public string DateAsString { get; set; }
}
public class MyDbContext : DbContext
{
public MyDbContext(string nameOrConnectionString) : base(nameOrConnectionString)
{
Database.SetInitializer<MyDbContext>(null);
}
public IDbSet<Table> TestData { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder
.Entity<Table>()
.ToTable("TestData")
.HasKey(x => x.Id)
.Property(x => x.Id).HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity);
modelBuilder.Entity<Table>().Property(x => x.Date);
}
}
public class Program
{
private 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 dbInit = new MyDbContext("Domain");
dbInit.Database.CreateIfNotExists();
var con = dbInit.Database.Connection;
con.Open();
LogPgInfo(dbInit, "Version", "select version()");
LogPgInfo(dbInit, "Timezone", "select current_setting('TIMEZONE') tz");
using (var db = new MyDbContext("Domain"))
{
var date = new DateTimeOffset(2018, 10, 28, 2, 40, 0, new TimeSpan(2, 0, 0));
var date2 = new DateTimeOffset(2018, 10, 28, 2, 40, 0, new TimeSpan(1, 0, 0));
db.TestData.Add(new Table { Id = 1, Date = date, DateAsString = date.ToString() });
db.TestData.Add(new Table { Id = 2, Date = date2, DateAsString = date2.ToString() });
db.SaveChanges();
}
}
private 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());
}
private static void LogPgInfo(MyDbContext store, string label, string command)
{
using (var cmd = store.Database.Connection.CreateCommand())
{
cmd.CommandText = command;
Console.WriteLine("Pg {0}:\t{1}", label, cmd.ExecuteScalar());
}
}
}
}
Output:
Code: Select all
Culture: Polski (Polska)
Timezone: (UTC+01:00) Sarajewo, Skopie, Warszawa, Zagrzeb
Dll Version: Devart.Data.dll, v5.0.2045.0
Dll Version: Devart.Data.PostgreSql.dll, v7.11.1253.0
Dll Version: Devart.Data.PostgreSql.Entity.EF6.dll, v7.11.1253.0
Pg Version: PostgreSQL 9.6.6, compiled by Visual C++ build 1800, 64-bit
Pg Timezone: Europe/Sarajevo