I have NHibernate XML mapping files that work wonderfully in MSSQL Databases. An example of a table is:
<class name="Worm" table="`Worms`" schema="`dbo`">
Now I need to use the exact same mapping file (unchanged) to generate a MariaDB (or MySQL) database. Clearly, such databases do not have schemas. So, what I'm trying to do is to create a naming convention so that the 'schema' becomes the prefix of a table, e.g. 'dbo_Worm'.
I've tried using the
var schemaUpdate = new NHibernate.Tool.hbm2ddl.SchemaUpdate(configuration);
by adding a custom Naming Strategy class into the 'configuration'. For now my custom class does nothing: just throws NotImplementedExceptions():
public class MyCustomNamingStrategy : INamingStrategy
{
public static MyCustomNamingStrategy Instance => new MyCustomNamingStrategy();
public string ClassToTableName(string className)
{
throw new NotImplementedException();
}
public string PropertyToColumnName(string propertyName)
{
throw new NotImplementedException();
}
public string TableName(string tableName)
{
throw new NotImplementedException();
}
public string ColumnName(string columnName)
{
throw new NotImplementedException();
}
public string PropertyToTableName(string className, string propertyName)
{
throw new NotImplementedException();
}
public string LogicalColumnName(string columnName, string propertyName)
{
throw new NotImplementedException();
}
}
The reasons are two:
- I've never reached the breakpoints of my MyCustomNamingStrategy class to begin with, so I don't even know if this is the way to go. Will it give me any information with regards to the 'schema'? I don't know...
- The code that calls the SchemaUpdate of the tool completely ignores the custom naming strategy and a MySQL Exception is thrown stating that no 'dbo' database is found (duh....)
Having tried everything and searched everywhere I'm turning to you for assistance. Can anyone help me
- Keep the exact same XML Mapping File, yet
- Produce tables prefixed with their schema names ?
Any hints would be greatly appreciated!