StoreGeneratedPattern="Computed"
在 timestamp
类型的列上完美运行。但是您不能将时间戳显示为人类可读的形式。
因此您不能向用户显示“此行已在 {TimeStamp}
上修改”,因为您根本无法将 SQL 时间戳解析为 DateTime。
现在我还可以为 DateTime
列创建计算列,这样我就不需要手动设置了吗?
myEntity.LastModification = DateTime.Now
更不用说它很容易出错,如果某些用户真的想做坏事,只需更改他的计算机时间即可。
最佳答案
摘录:
...If you set the StoreGeneratedPattern to Identity (if the value is only computed on insert) or Computed (if it is computed on every update), then when you call SaveChanges the EF will get the value generated in the database and bring it back to update your object...
编辑:要使数据库服务器端修改日期更新,请遵循此答案 https://stackoverflow.com/a/8461681/1679310 . Computed
设置将重新加载
关于c# - 在 Entity Framework 中使用计算的 DateTime 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13875784/