0

I get this error when using linq-to-sql with timestamp as part of a composite primary key:

"The primary key column of type 'Timestamp' cannot be generated by the server."

I'm guessing this may be due to the fact timestamp is just a row version thus perhaps it must be created after the insert? Or...

2 Answers 2

5

don't use the timestamp data type!!

The timestamp syntax is deprecated. This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

timestamp (Transact-SQL) http://msdn.microsoft.com/en-us/library/ms182776(SQL.90).aspx rowversion (Transact-SQL) http://msdn.microsoft.com/en-us/library/ms182776.aspx

Also, if it primarily designed to change, to keep track of versions, why make it a part of a primary key? changing a primary key can cause many problems!

If you need a system generated value for a primary key, use an identity or guid.

IDENTITY (Property) http://msdn.microsoft.com/en-us/library/aa933196(SQL.80).aspx
GUID uniqueidentifier http://msdn.microsoft.com/en-us/library/aa260656(v=SQL.80).aspx

4
  • @KM Thanks for the info but doesn't linq-to-sql require timestamp for optimistic concurrency for detached objects? The main reason I'm doing this is that I really don't need a primary key for this table or rather I don't care if there are duplicate entries provided that not every field is duplicated. Basically, I'm using this as a token storage for a password recovery and the user may request password multiple times. I just store a new token in the table versus because I don't want to check if it already exists. Apr 12, 2010 at 18:39
  • @KM Also rowversion is not an option in Visual Studio 2008. Apr 12, 2010 at 18:42
  • try making the PK an identity and the timestamp just a column, like in this example: mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/… see this link about rowversion thedatafarm.com/blog/data-access/…
    – KM.
    Apr 12, 2010 at 18:47
  • @Curtis: LINQ-to-SQL does use the timestamp/rowversion column for optimistic concurrency checks, but the LINQ engine automatically scans the table schema to see if one is present. Since MSSQL only allows one timestamp/rowversion field per table, it's an easy check. Regarding VS2008, you can't enter rowversion as a data type, but timestamp is converted to rowversion behind the scenes.
    – Neil T.
    Apr 12, 2010 at 18:55
0

You can work around it.. set

  • Auto Generated Value to True
  • Auto-Sync to OnInsert

...unless you already have of course

1
  • @gbn Thanks. Sounds like that could work but I'll probably just not use it in the PK because I don't want to modify the DBML. Apr 12, 2010 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.