Linq to sql error with identitiy increment field

13,745

Solution 1

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.

Solution 2

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"

Solution 3

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

Solution 4

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.

Solution 5

On insert option is set only when you are inserting values in database. If you have not any issue with security option with data base then always use Never option in data base.

Share:
13,745

Related videos on Youtube

Dave Turvey
Author by

Dave Turvey

Updated on April 17, 2022

Comments

  • Dave Turvey
    Dave Turvey about 2 years

    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

  • jeremcc
    jeremcc about 15 years
    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.