none
issue with autoincrement ID RRS feed

  • Question

  •  

    Hello everyone

     

    I'm starting to deal with linq on an SQL/Object mapping... And I got a question: On my SQL table, I got an ID field that's autoincrement, primary key. This field is in my object aswell.... so far so good... no problem. 

     

    The object is then used to feed a BindingSource which feeds a DataGridView... which of course shows up the ID field... there is the issue, first row in the DataGridView, I get an ID of 0 (it's an int... normal...) but when I DataContext.SubmitChanges I get an error (of course, an ID of 0 is not accepted... and even so, it's not the code that should give the id...)

     

    So... My question is... how do I prevent such behavior ?

     

     

    Thank you

     

    Tuesday, June 3, 2008 1:13 AM

Answers

  • Hi pierreact,

    Do you actually see that your ID is assigned properly when you debug ? Or is it a new record ? If it is new, then check  the attribute of the ID field in the designer file, there should be a field like IsDbGenerated=true. In this case it ignores the new id and uses the scope identity to populate the id field.

    As said, if this doesn't help, posting your code can give some idea.
    Tuesday, June 3, 2008 10:12 AM

All replies

  • If you post the code it might help to understand the issue better.

     

    Tuesday, June 3, 2008 3:37 AM
  • Hi pierreact,

    Do you actually see that your ID is assigned properly when you debug ? Or is it a new record ? If it is new, then check  the attribute of the ID field in the designer file, there should be a field like IsDbGenerated=true. In this case it ignores the new id and uses the scope identity to populate the id field.

    As said, if this doesn't help, posting your code can give some idea.
    Tuesday, June 3, 2008 10:12 AM