I have a table called “master_._clients” in a Postgres database. Note the . as part of the table. This is causing issues when trying to run a query like Db.Select().ToList() using SS OrmLite.
C# Dto class as per below
[Alias("master.Clients")]
public class DbClient
{
public int Id { get; set; }
}
I am unable to query this table using ServiceStack OrmLite using the latest version of SS as the db command created is resulting in a raw SQL query that looks like this. Note, it worked on previous versions.
Exception:
“42P01: relation “master_._clients” does not exist”
Stack trace:
" at Npgsql.NpgsqlConnector.g__ReadMessageLong|194_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)\r\n at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)\r\n at Npgsql.NpgsqlDataReader.NextResult()\r\n at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)\r\n at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)\r\n at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior)\r\n at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)\r\n at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()\r\n at ServiceStack.OrmLite.OrmLiteCommand.ExecuteReader() in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteCommand.cs:line 51\r\n at ServiceStack.OrmLite.OrmLiteReadCommandExtensions.ExecReader(IDbCommand dbCmd, String sql) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteReadCommandExtensions.cs:line 42\r\n at ServiceStack.OrmLite.OrmLiteResultsFilterExtensions.ConvertToList[T](IDbCommand dbCmd, String sql) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteResultsFilterExtensions.cs:line 98\r\n at ServiceStack.OrmLite.OrmLiteReadCommandExtensions.Select[T](IDbCommand dbCmd, String sql, Object anonType) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteReadCommandExtensions.cs:line 485\r\n at ServiceStack.OrmLite.OrmLiteReadCommandExtensions.Select[T](IDbCommand dbCmd) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteReadCommandExtensions.cs:line 77\r\n at ServiceStack.OrmLite.OrmLiteReadApi.<>c__01.<Select>b__0_0(IDbCommand dbCmd) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteReadApi.cs:line 17\r\n at ServiceStack.OrmLite.OrmLiteExecFilter.Exec[T](IDbConnection dbConn, Func2 filter) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteExecFilter.cs:line 66"
This implementation has long since been changed to support the more common use-case of quoted names containing schema & table names.
You should be able to restore old behavior with a custom Dialect Provider, e.g:
public class MyPostgreSqlDialectProvider
: ServiceStack.OrmLite.PostgreSQL.PostgreSqlDialectProvider
{
public static MyPostgreSqlDialectProvider Instance = new();
public override string GetQuotedName(string name) => string.IsNullOrEmpty(name)
? null : name[0] == '"' ? name : '"' + name + '"';
}
// Use instead of PostgreSqlDialect.Provider
var dbFactory = new OrmLiteConnectionFactory(
connStr, MyPostgreSqlDialectProvider.Instance);