Page 1 of 1

Another UTC Offset issue.

Posted: Wed 12 Nov 2014 22:07
by agillesp
Use the following to reproduce the issue:

Code: Select all

using System;
using System.Linq;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;

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 class Projection
    {
        public int id { get; set; }
        public DateTimeOffset date { get; set; }
    }

    public class Store : DbContext
    {
        public Store(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {
        }

        public IDbSet<Data> Data { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder
                .Entity<Data>()
                .ToTable("data")
                .HasKey(x => x.Id)
                .Property(x => x.Id)
                .HasColumnName("id")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            modelBuilder.Entity<Data>().Property(x => x.Date).HasColumnName("date");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var name = "Your Connection Name";
            var store = new Store(name);

            store.Data.Add(new Data { Date = new DateTime(1971, 11, 2) });
            store.SaveChanges();

            // Causes - "The UTC Offset of the local dateTime parameter does not match the offset argument."
            var data = store.Data.Select(x => new Projection
            {
                date = x.Date,
                id = x.Id
            })
            .ToArray();
        }
    }
}

Re: Another UTC Offset issue.

Posted: Fri 14 Nov 2014 11:42
by MariiaI
We couldn't reproduce this issue with the latest build of dotConnect for PostgreSQL 7.3.283.
Please provide us with the following information:
- the version of dotConnect for PostgreSQL you are using;
- the PostgreSQL server version;
- the regional settings on your system and the regional and date format settings that are used on the server;
- the full stack trace of the exception;
- the generated SQL query: https://www.devart.com/dotconnect/postg ... nitor.html , etc.

Re: Another UTC Offset issue.

Posted: Tue 18 Nov 2014 17:50
by agillesp
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());
            }
        }
    }
}

Re: Another UTC Offset issue.

Posted: Wed 19 Nov 2014 12:42
by MariiaI
Thank you for the additional information. We have reproduced this issue. We will investigate it and inform you about the results as soon as possible.

Re: Another UTC Offset issue.

Posted: Sun 30 Nov 2014 23:16
by agillesp
Hello, has there been any updates with this?

Re: Another UTC Offset issue.

Posted: Mon 01 Dec 2014 06:37
by MariiaI
agillesp wrote:Hello, has there been any updates with this?
We have fixed this issue. The fix will be included in the next public build of dotConnect for PostgreSQL, which we plan to release this week. We will inform you when it is available for download.

Re: Another UTC Offset issue.

Posted: Mon 01 Dec 2014 08:05
by agillesp
OK, thank you. I hope this fixes another issue that I've seen too when I set the timezone offset via:

Code: Select all

Devart.Data.PostgreSql.PgSqlLocalization.TimeZone = "+8";
I was getting the exact same exception but I'll hold off filing the bug until I get a chance to test the new build.

Re: Another UTC Offset issue.

Posted: Tue 02 Dec 2014 12:44
by MariiaI
agillesp wrote:OK, thank you. I hope this fixes another issue that I've seen too when I set the timezone offset via:

Code: Select all

Devart.Data.PostgreSql.PgSqlLocalization.TimeZone = "+8";
Thank you for the additional information.
We will inform you when new build of dotConnect for PostgreSQL with the fixes is available for download.

Re: Another UTC Offset issue.

Posted: Fri 05 Dec 2014 07:19
by MariiaI
New build of dotConnect for PostgreSQL 7.3.303 is available for download now!
It can be downloaded from http://www.devart.com/dotconnect/postgr ... nload.html (trial version) or from Registered Users' Area (for users with valid subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=3&t=30898.