Note that there are some explanatory texts on larger screens.

plurals
  1. PONDbUnit does not set a primary key field specified in the XML when the column is an Identity column
    text
    copied!<p>I am using NDbUnit to unit test my data access layer.</p> <p>Everything has been working fine when constructing the XSD and associated XML files that are used to populate various tables with rows of data. However I have just noticed that I am unable to set the PK directly through XML for an integer PK column when it is an identity column. </p> <p>i.e. When the database automatically handles incrementing and setting the PK on a row insertion, NDbUnit isn't able to override this and set it itself (as far as I can see).</p> <p>Is there some way for NDbUnit to override this identity column value and set it directly from the XML or am I stuck with the auto-incremented value that SQL Server creates for the inserted row? Or is there another pattern that I should use to insert a row with an identity column and then subsequently use that value as the FK on another table's row?</p> <hr> <p><strong>Update:</strong> </p> <p>I discovered that when you perform the NDbUnit database operation you need to set the parameter to InsertIdentity not just Insert:</p> <pre><code>INDbUnitTest database = new NDbUnit.Core.SqlClient.SqlDbUnitTest(connectionString); database.PerformDbOperation(DbOperationFlag.InsertIdentity); </code></pre> <p>However even after I made this change, I now get the following error as the rows are being inserted:</p> <blockquote> <p>Cannot insert explicit value for identity column in table 'myTable' when IDENTITY_INSERT is set to OFF.</p> </blockquote> <p>This would leave me to believe that the InsertIdentity flag being set on the NBDUnit method is not actually setting the IDENTITY_INSERT to OFF for the specific table within SQL Server.</p> <p>Any suggestions on why this wouldn't be happening?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload