Let’s say I do a query against my context to retrieve a particular entity.
Now I’d like to find the best way to know if the corresponding row in the database (let’s stay simple with a 1-1 mapping between entity and SQL Table) has changed since the creation of my entity.
I’ve thought about using a TimeStamp column and execute a simple query each each I want to know if the entity is outdated, like:
var uptodate = (from e in context.mySet
where e.TimeStamp == entityTimeStamp
select e).Any();
By indexing the TimeStamp column, I think it would be a fast way to go, but unfortunately I didn’t find any confirmation around the internet…
After further tests and investigation using the TimeStamp and a query to know if it’s still the same (more precisely if the given value is still in the table) seems the best way to go.
Such mechanism needs an index on the TimeStamp column to ensure the best performance (roughly O(Log(n) instead of (O(n)).