I'm running an NHIbernate solution using SQL CE. I am mapping one the fields in a table as below. However, in order to run some data imports I need to be able to temporarily turn off identity so I can import the data with its existing keys, then turn identity back on once the import has finished.
I've tried running a SQL query directly from the solution like this:
session.CreateSQLQuery(@"SET IDENTITY_INSERT [Article] ON");
but this seems to have no effect.
Is there any way to temporarily turn this on and off?
Property(x => x.ArticleId, m =>
{
m.NotNullable(true);
m.UniqueKey("UQ_Article_ArticleId");
m.Column(cm => cm.SqlType("INT IDENTITY"));
m.Generated(PropertyGeneration.Insert);
m.Insert(true);
m.Update(false);
});