By Buluc Celik - 2/15/2010
Hi,
I am getting the following error while trying to insert a record using businessObject1.save():
Cannot insert explicit value for identity column in table 'MyTable' when IDENTITY_INSERT is set to OFF.
I tracked the problem and found out that the SQL generated to insert the record has the auto-increment primary id field set to NULL.
Things I tried:
1. I setted the ID field to readonly from the Business Object Mapper -> same error
2. I captured the exact SQL, removed the ID field and run it on SQL Server Management Studio -> worked at that run
3. I added the ID field to FieldsToExcludeFromInsert property of the business object -> the application gave the error: Cannot create INSERT command because the updating DataTable does not contain columns for all PrimaryKeyFields.
I compared the business object I created for that application with a business object from the samples - which also has a auto-increment primary key field (cust_pk), and it seems to have the same structure. I didn't see any difference that could be the reason of the problem I am having.
I am still trying to find the problem, but any help would be very much appreciated.
Thanks,
Buluc
|
By Trent L. Taylor - 2/15/2010
If you are doing this through a BO, then you need to set the PrimaryKeyIsUpdatable property to True and the PrimaryKeyIsAutoIncremented to False.
|
By Buluc Celik - 2/15/2010
Thanks Trent, you pointed to the right direction. I have removed the PK from the FieldsToExcludeFromInsert property, then set PrimaryKeyIsAutoIncremented to TRUE and PrimaryKeyIsUpdatable to FALSE. It is working now
|
By Trent L. Taylor - 2/16/2010
Glad you got it figured out
|
|