updating record timestamp with linqtosql
I have a some tables that include a lastupdatedate fiel, the idea being that anytime the information in a row is altered, the lastupdatedate will be reset to the current date/time Setting lastupdatedate using the client side's current datetime is not a good idea. For starters, they may be in different time zones. Although I could solve this problem by storing UCT however a more serious issue is th开发者_如何学Goat the clocks of different users will not all be synchronized. What makes more sense is to just use GETDATE() for the lastupdate parameter in the SQL Update command. This way you are guaranteed that all lastupdatedate values will be relative to the same clock, the one on the SQL server.
In ADO.NET this was easy because you directly submitted a SQL statement to be executed but in LinqToSQL you would typically do SubmitChanges.
Is there any easy way to do this with linqtosql outside of creating a stored procedure ?
Another option you could consider would be to create a Scalar function on the database server which exposes that server's current time. You map that scalar function to a LINQ to SQL function and call that method to get your server's time to set the lastupdatedate on your object prior to SubmitChanges.
I also store last modified date and will grab the data from the web server. It has worked fine so far. If your code is running on only one web server, then the LinqToSQL is executed on that server, therefore you will a have a consistent time source. Will that work?
精彩评论