0

When using EF code first, is there a way to tell SQL Server to assign SYSUTCDATETIME() to a table column that corresponds to a DateTime property in the entity class I'm saving to the database.

If not, then how to solve the issue of having your C# code running on a server farm, where farm nodes can have slightly different system time. As a result, if e.g. Node1 is slightly ahead of Node2 and makes some database change slightly before Node2, the timestamp of the change made by Node1 can be greater than the timestamp of the change made by Node2, even though the actual change happened earlier.

11
  • So what is the problem? Commented Jul 19, 2017 at 11:26
  • Possible duplicate of Possible to default DateTime field to GETDATE() with Entity Framework Migrations? Commented Jul 19, 2017 at 11:36
  • Thanks @DavidG, the link you provided seems to be only covering inserting new records. How do I do this for updates as well? Commented Jul 19, 2017 at 14:47
  • There isn't even a way to do that in SQL Server directly without a trigger. What exactly do you mean? Commented Jul 19, 2017 at 14:49
  • @DavidG The problem is that if I insert to table A and then use the ID of the new record to update an existing record in table B, CreateDate in A can be later than the LastModified date in B. So I just used an ID from A in B before that ID appeared in A. This can mess up some reporting. Commented Jul 19, 2017 at 14:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.