just want to know if linq to sql auto updated the id column of a class (table row object) after SubmitChanges is called inserting a new row to that table, that would be fantastic, would anyone be able to confirm this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can verify that an IDENTITY column will be updated on
SubmitChanges()by looking at the[Column]attribute for the mapped property (or<Column>element if you are using an external XML mapping file).There are two properties that will be set on the
[Column]attribute,IsDbGenerated = true, andAutoSync = OnInsert– the first attribute tells LINQ that the target column’s value is created by the database such as for IDENTITY columns or TIMESTAMP / ROWVERSION columns, and the latter tells LINQ to update the model object with the value after a database insert.Both properties need to be set like this for the expected behaviour to occur. If you use SqlMetal or the Visual Studio designer, the generated code will normally handle this for you automatically, as long as the column was IDENTITY or TIMESTAMP to begin with. If you change the column to an IDENTITY type later on, you will either need to regenerate the LINQ code, or update the attributes manually yourself.