Finding updated entry with Entity Framework Timestamp using code first

ぐ巨炮叔叔 提交于 2019-12-11 02:12:19

问题


One of my models, let's call it "Comment" has a timestamp column/member

I had defined it originally as:

[Required]
public DateTime Timestamp { get; set; }

I had some methods in other parts of my code that would get the latest comments after a specific time, so it would grab all comments with a timestamp greater than some value.

I recently came across an article by Julie Lerman about the timestamp data annotation for entity framework (http://msdn.microsoft.com/en-US/data/jj591583#c_8b121aeb433a4ab19d538bc8c20a58fb) and she suggested using a byte array with the [Timestamp] data annotation for correct storage in the database.

[Timestamp]
public Byte[] Timestamp { get; set; }

I am not sure how to handle finding updated records with the byte array. From what I understand, the system handles timestamp byte arrays by just incrementing them by 1 every time they are updated, but that is a relative value.

What am I missing?


回答1:


Sounds like you're not using the Timestamp property as a concurrency check but as a standard property. I'd revert back to a DateTime



来源:https://stackoverflow.com/questions/18279614/finding-updated-entry-with-entity-framework-timestamp-using-code-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!