0

I would like to strictly convert DateTime Values to UTC when target Column is a DateTime2 DB Type.

Found some resources which are mentioning the .SetConverter - Method.

But whatever i do (As you can see in my code below i was trying to specify the columns) the converter code doesn't get hit...

...
 MappingSchema.Default.SetConverter<DateTime, DateTime>(x => {
                    return DateTime.SpecifyKind(x, DateTimeKind.Utc);
                }
                , new DbDataType(typeof(DateTime)), new DbDataType(typeof(DateTime), LinqToDB.DataType.DateTime2));
...

Table Schema:

CREATE TABLE [dbo].[RTP_Import](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [UserId] [int] NOT NULL,
    [Timestamp] [datetime2](7) NOT NULL,
    [ChangedRowsCount] [int] NOT NULL,
    [ChangedCellsCount] [int] NOT NULL,
    [Rows] [int] NOT NULL,
 CONSTRAINT [PK_RTP_Import] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)

Model:

    [Table(Schema = "dbo", Name = "RTP_Import")]
    public partial class RTPImport : ITable
    {
        [PrimaryKey]
        [Identity]
        public int Id { get; set; }
        [Column]
        public int UserId { get; set; }
        [Column]
        public int Rows { get; set; }
        [Column]
        public int ChangedRowsCount { get; set; }
        [Column]
        public int ChangedCellsCount { get; set; }
        [Column]
        public DateTime Timestamp { get; set; }

    }
fops
  • 384
  • 1
  • 13

0 Answers0