A column with timestamp field type is useful to record user activity. However, as timestamp values are binary numbers it is difficult to compare with other datetime values.
A datetime column can also be used like a timestamp field to record the exact date and time by enforcing the datetime column to be not null and set its default value with getdate() function.
If you’re using Linq in your program, remember to explicitly set the Auto Generated Value property of the datetime column in the Linq to Sql designer to True after dragging the table containing the datetime field onto the .dbml view.
This is because Linq to SQL by default will not select the default value in your database and try to insert the NULL value into the datetime field. Therefore, your program will raise an error like: “Cannot insert NULL value into …”
No comments:
Post a Comment