如何使用ADO.NET Entity Framework自动更新ModifiedAt字段?

时间:2021-10-10 06:49:35

Ruby on Rails has magic timestamping fields that are automatically updated when a record is created or updated. I'm trying to find similar functionality in Entity Framework. I've considered database triggers and a SavingChanges event handler. Is there a more obvious method I'm overlooking?

Ruby on Rails具有魔术时间戳字段,在创建或更新记录时会自动更新这些字段。我正在尝试在Entity Framework中找到类似的功能。我考虑过数据库触发器和SavingChanges事件处理程序。有没有更明显的方法我忽视?

2 个解决方案

#1


0  

If you're using MS SQL Server, use a timestamp field. The value itself is meaningless, other than to tell you whether the record has been touched since your last retrieve.

如果您使用的是MS SQL Server,请使用时间戳字段。除了告诉您自上次检索后是否已触摸记录以外,该值本身没有意义。

#2


0  

I resorted to a SavingChanges event handler. Details on my blog.

我使用了SavingChanges事件处理程序。我博客上的详细信息。

#1


0  

If you're using MS SQL Server, use a timestamp field. The value itself is meaningless, other than to tell you whether the record has been touched since your last retrieve.

如果您使用的是MS SQL Server,请使用时间戳字段。除了告诉您自上次检索后是否已触摸记录以外,该值本身没有意义。

#2


0  

I resorted to a SavingChanges event handler. Details on my blog.

我使用了SavingChanges事件处理程序。我博客上的详细信息。