Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq to sql error with identitiy increment field

I've just started to use linq to sql and have run into a problem with inserting a record with an auto incrementing field.

I have created a new instance of a company object defined by linq. it has initialised an auto incrementing field 'companyID' to 0. InsertOnSubmit() fails with the following invalidOperationException.

Incorrect autosync specification for member 'companyID'

the column attribute IsDbGenerated is true for the companyID property. I am using sql server 2000.

Edit: Auto-sync is set to OnIsert. The dataype is BigInt in TSQL, long in c#.

Does anyone know why this error is occuring and how it can be resolved?

thanks

like image 445
Dave Turvey Avatar asked Dec 11 '08 09:12

Dave Turvey


1 Answers

Found the answer. It was to do with primary keys. In the linq designer the primary keys were setup as they should be. In the database the relevant fields were not set as primary keys. I fixed the keys in the databse and this resolved the problem.

like image 77
Dave Turvey Avatar answered Oct 12 '22 04:10

Dave Turvey