Not getting key value from Identity column back after inserting new row with SubSonic ActiveRecord

Posted by mikedevenney on Stack Overflow See other posts from Stack Overflow or by mikedevenney
Published on 2010-05-21T16:28:24Z Indexed on 2010/05/25 13:01 UTC
Read the original article Hit count: 201

Filed under:
|

I'm sure I'm missing the obvious answer here, but could use a hand. I'm new to SubSonic and using version 3. I've got myself to the point of being able to query and insert, but I'm stuck with how I would get the value of the identity column back after my insert. I saw another post that mentioned Linq Templates. I'm not using those (at least I don't think I am...?)

TIA

... UPDATE ...

So I've been debugging through my code watching how the SubSonic code works and I found where the indentity column is being ignored. I use int as the datatype for my ID columns in the database and set them as identity. Since int is a non-nullable data type in c# the logical test in the Add method (public void Add(IDataProvider provider)) that checks if there is a value in the key column by doing a (key==null) could be the issue. The code that gets the new value for the identity field is in the 'true path', since an int can't be null and I use ints as my identity column data types this test will never pass. The ID field for my object has a 0 in it that I didn't put there. I assume it's set during the initialization of the object. Am I off base here? Is the answer to change my data types in the database?

Another question (more a curiosity). I noticed that some of the properties in the generated classes are declared with a ? after the datatype. I'm not familiar with this declaration construct... what gives? There are some declared as an int (non key fields) and others that are declared as int? (key fields). Does this have something to do with how they're treated at initialization?

Any help is appreciated!

--BUMP--

© Stack Overflow or respective owner

Related posts about subsonic3

Related posts about identity-column