Aaron
July 30, 2017, 4:08am
1
Hi,
Any reason the Schema attribute for MySQL Provider just prepends a text to the table rather than do a full quoted schema reference?
For example:
[Schema("myschema")] class table { ...
does: `myschema_table`
when it should do: `myschema`.`table`
mythz
July 30, 2017, 4:11am
2
A Schema is not the same thing in MySql compared with other databases, it’s more like a different database so we use it’s used as a namespace alias instead.
Aaron
July 30, 2017, 4:24am
3
Oh I see, I remember now that in SQL Server a schema is like a namespace separation and not a separate database. Okay so this attribute was never intended for cross database access. For example a SqlExpression query that references two different databases on the one db server?
mythz
July 30, 2017, 4:29am
4
Right, OrmLite doesn’t do anything special to enable cross DB queries, it just sends the SQL to the RDBMS.
Aaron
July 30, 2017, 4:49am
5
Just off the top of your head if I did override this, might it work?
public class CustomMySqlDialectProvider : MySqlDialectProvider
{
public override string GetTableName(string table, string schema = null)
{
if (schema == null) {
return NamingStrategy.GetTableName(table);
} else {
return $$"{NamingStrategy.GetSchemaName(schema)}.{NamingStrategy.GetTableName(table)}";
}
}
public override string GetQuotedTableName(string tableName, string schema = null)
{
if (schema == null) {
return $$"`{NamingStrategy.GetTableName(tableName)}`";
} else {
return $$"`{NamingStrategy.GetSchemaName(schema)}`.`{NamingStrategy.GetTableName(tableName)}`";
}
}
}
Also requires in AppHost for me:
var databaseProvider = new CustomMySqlDialectProvider();
MySqlDialectProvider.Instance = databaseProvider;
OrmLiteConfig.DialectProvider = databaseProvider;
mythz
July 30, 2017, 4:51am
6
That’s what you need to do to modify the generated SQL yes.