Issues after upgrading Service Stack from 3.9.71 to 6.8.0

I have upgraded the ServiceStack and the dependent packages to the latest but I am getting some issues with the RDMS side wherein, after refreshing all tables entities via .tt files. The issue is that there are a few columns in the database which are having names such as 1st Reminder, 2nd Reminder, etc. The application is automatically creating the properties like as below and throwing Invalid token errors. We are looking for help on how to fix this error.

Ok sounds like this is being generated by ServiceStack.OrmLite.T4 which hasn’t been touched in years. The recommended OrmLite Data Model generation now is to use AutoGen.

But if you just want to preserve the existing behavior I would just go back to using the v3 version of the T4 templates you were using before which you can get from the v3 branch from:

Which you can copy into your project instead of referencing the ServiceStack.OrmLite.T4 NuGet package.

Out of curiosity what was the code generation for these columns previously?

I just found that in my file, the following changes were missing. I modified these changes and now it is replacing @ with underscore (“_”).
static Func<string, string> CleanUp = (str) =>
str = rxCleanUp.Replace(str, “_”);

if (char.IsDigit(str[0]))
	str = "_" + str;
else if (cs_keywords.Contains(str))
	str = "@" + str;

return str;


I am getting now few different issues which are listed as below: -

  • OrmLiteConfig.TSTransaction - This static variable is no longer available in the new version. Now, the application is throwing an error while reading this variable. How can I fix this now irrespective of using the old version?
    dbCommand.Transaction = OrmLiteConfig.TSTransaction!= null ? (DbTransaction)OrmLiteConfig.TSTransaction : null;

  • The following extension method are no longer available. What should I do now?
    They are not even available in ServiceStack.OrmLite.Dapper
    I am using Dapper for following extension method because that is also not available after the upgradation to 6.8
    Db.SingleOrDefault → Db.QuerySingleOrDefault

You can get the current transaction with:

var trans = db.GetTransaction();

Although you’d normally already have the reference from the transaction when you open it:

using (var trans = db.OpenTransaction())

You can find different Query APIs from OrmLite Select APIs docs, e.g. you’d use db.Single* APIs to fetch a single row:

var result = db.SingleById<Table>(id);

Insert records with AutoIncrement Ids docs. Instead of using GetLastInsertId() you should use selectIdentity:true with db.Insert():

var id = db.Insert(row, selectIdentity:true);

Or you can use db.Save() which populates the AutoIncrement PrimaryKey

db.Save(row); // Populates row.Id

For Db.SingleOrDefault just remove OrDefault from your APIs, every Single* API that doesn’t have a record returns null.

Thanks for providing all details. I got the fixes for all other issues but can you please help to replace the below commented line with something?
If I am not wrong then you have suggested that I add the below changes for the commented line
dbCommand.Transaction = dbConnection.GetTransaction();

public static OrmLiteSPStatement SP_GetResult(this IDbConnection dbConnection )
    DbCommand dbCommand = (DbCommand)dbConnection.CreateCommand();
    dbCommand.CommandText = "SP_Test";
    dbCommand.CommandType = CommandType.StoredProcedure;
    //dbCommand.Transaction = OrmLiteConfig.TSTransaction!= null ? (DbTransaction)OrmLiteConfig.TSTransaction : null;
    return new OrmLiteSPStatement(dbCommand);

That looks like it’s just executing a stored procedure, we’ve got some Stored Procedure Usage examples in the docs.

To return the same OrmLiteSPStatement you can use GetTransaction(), e.g:

public static OrmLiteSPStatement SP_GetResult(this IDbConnection dbConnection)
    DbCommand dbCommand = (DbCommand)dbConnection.CreateCommand();
    dbCommand.CommandText = “SP_Test”;
    dbCommand.CommandType = CommandType.StoredProcedure;
    dbCommand.Transaction = dbConnection.GetTransaction();
    return new OrmLiteSPStatement(dbCommand);
1 Like

Hi Guys, I am not getting the following which seems to me related to the license. I already added the license in the system variable but still the error is coming. Can anyone help me on this please? We are only getting this error in the one server but not in other server with same .net framework assemblies.

at ServiceStack.NetFxPclExport.RegisterLicenseFromConfig()
at ServiceStack.LicenseUtils…cctor()
— End of inner exception stack trace —
at ServiceStack.LicenseUtils.get_Info()
at ServiceStack.Text.Env.UpdateServerUserAgent()

What’s the full StackTrace?

If the license is registered it could be masquerading the underlying exception that’s causing the issue.

The issue lies somewhere else. There were few dependent packages missing in one of the project. I installed the required packages and then, the issue resolved. Thanks

1 Like