locked
Entity Framework Override the DateTime Proprties into UTC RRS feed

  • Question

  • Hi

    I am using EF 6.1 with Code First Model Approach.

    We have created the database with more than 150 tables .

    Now whenever i save the data in the database , i want to store date-time value into UTC.

    How to do that without co-refactoring.

    Can i override the Datetime datatype of Entity Framework and  set the format in UTC.

    Thanks in Advance

    Regards

    Baskar.G


    • Edited by baskarg83 Saturday, June 25, 2016 1:35 PM
    Saturday, June 25, 2016 1:35 PM

Answers

All replies

  • You can tell EF for a given property in an EF entity to ignore the property when said EF entity is persisted to the DB table. It would mean that you would be using an Insert or Update trigger with logic in the trigger at the DB engine level to format the date as needed upon Insert or Update.

    It use to be the Compute attribute prior to EF 6 that told EF to ignore the property during the insert/update process of persisting said object to the DB table. What it is now for EF 6 I don't know, but  there was a recent post in the forum with a resolution post about it. You'll have to search for the thread.

    Saturday, June 25, 2016 4:51 PM
  • >Can i override the Datetime datatype of Entity Framework and  set the format in UTC.

    I'm not sure I understand your question.

    UTC is not a separate datatype.  EF doesn't assign datetime values for you, and you can set them to UTC values if you wish.

    David


    David http://blogs.msdn.com/b/dbrowne/

    Saturday, June 25, 2016 7:06 PM