CreateTableIfNotExists errors trying to query empty sequence?

Hi

I am seeing a new error in two different projects whereby creating tables with CreateTableIfNotExists in sql server is failing, seemingly because of the use of the AutoIncrement attribute on the PK property.

I am on a train now so having a hard time connecting to repos to investigate latest changes, but I can trigger this error every time using the table:

public class MyTable
{
	[AutoIncrement]
	public int MyId { get; set; }
}

and in the db initialization step:

using (var db = dbConnectionFactory.OpenDbConnection())
		{
			db.CreateTableIfNotExists<MyTable>();
}

Using the tracing tools, I can see the following scripts being run:

SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'MyTable'

SELECT 1 FROM SYS.SEQUENCES WHERE object_id=object_id(N'')

and finally:

CREATE SEQUENCE "" AS BIGINT START WITH 1 INCREMENT BY 1 NO CACHE;

which is the line that actually fails.

I am currently using the SqlServer2012OrmLiteDialectProvider initializer, if that helps.

I’ll can investigate more later, but are you aware of any recent work that might be causing this suddenly? It’s interesting to note that a number of other tables in the second project ARE created successfully, but they use a manually created PK value , rather than an autoincrementing attribute on the PK. I.e. this works:

 public class MyTable
{
	[PrimaryKey]
	public int MyId { get; set; }
}

Sequence support was recently contributed to SQL Server 2012 in OrmLite which was causing this. Should be fixed with the latest v5.0.3 that’s now available on MyGet.

I’ve found and resolved more issues with SQL Server 2012 so if you download the latest v5.0.3 from MyGet it should resolve all outstanding issues.

1 Like