0

I have a simple table with 2 date time fields

These are setup within my objects with valid dates

However, when saving the values are getting generated by entity framework as 0001-01-01 00:00:00

What can cause this?

I am using Entity Framework Core against SQL Server 2016

Please see the image below which proves I have valid dates

I have noticed that the date is shown in USA format not sure if thats an issue?

enter image description here

I am not using an edmx, I have tried [Column(TypeName = "datetime2")] above the columns as well as trying with the column being both nullable and not nullable

My insert code is below

    using (var db = new MydbContext(connectionsString))
    {
        var rawItem = db.tblItem.FirstOrDefault(x => x.ItemId== createItem.Item.ItemId);
        if (rawItem == null)
        {
            rawItem = new tblItem();
            db.tblItem.Add(rawItem);
        }

        rawItem.ItemdDateTime = message.Item.ItemDateTime;
        rawItem.ProcessedDateTime = message.Item.ProcessedDateTime;

        await db.SaveChangesAsync();
    }

Paul

Paul
  • 2,773
  • 7
  • 41
  • 96

0 Answers0