views:

3623

answers:

4

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

+1  A: 

What is the value of the 'Auto-Sync' property on that class/table?

I just checked on my side, and it is set to 'OnInsert'. Also the 'Auto Generated Value' is set to true.

leppie
+1  A: 

What is the data-type? int? (int both TSQL and in C#?)

What auto-sync setting do you have? For a primary key, it should be "OnInsert"

Marc Gravell
+4  A: 

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.

Dave Turvey
It sounds like you edited the L2S file manually. I would recommend always letting the file be generated from your database automatically (using sql metal or the designer). Editing it directly allows inconsistencies to occurr, as you see here.
jeremcc
A: 

Same issue. Setting the primary key in the DB and changing AutoSync property to "OnInsert" on DBML helped

ingamx