mysql - Enable hbm2ddl.keywords=auto-quote in Fluent NHibernate -


i have made tiny software tool allows me display or run sql generated nhibernate. made because hbm2ddl.auto not recommended production.

i have 1 problem: when generate sql infamous index column unquoted, because need .aslist() mappings. prevents me run sql.

in theory, if had xml configuration of nhibernate use hbm2ddl.keywords tag, unfortunately since tool designed dba-supporting tool multiple environments, must use programmatic approach.

my approach (redundant) following:

private static configuration buildnhconfig(string connectionstring, dbtype dbtype, out dialect requireddialect)     {         ipersistenceconfigurer persistenceconfigurer;          switch (dbtype)         {             case dbtype.mysql:                 {                     persistenceconfigurer =                         mysqlconfiguration                         .standard                         .dialect<mysql5dialect>()                         .driver<mysqldatadriver>()                         .formatsql()                         .showsql()                         .connectionstring(connectionstring);                      requireddialect = new mysql5dialect();                     break;                 }             case dbtype.mssqlazure:                 {                     persistenceconfigurer = mssqlconfiguration.mssql2008                         .dialect<mssqlazure2008dialect>()                         .driver<sqlclientdriver>()                         .formatsql()                         .showsql()                         .connectionstring(connectionstring);                      requireddialect = new mssqlazure2008dialect();                     break;                 }             default:                 {                     throw new notimplementedexception();                 }         }           fluentconfiguration fc = fluently.configure()             .database(persistenceconfigurer)             .exposeconfiguration(                 cfg => cfg.setproperty("hbm2ddl.keywords", "keywords")                             .setproperty("hbm2ddl.auto", "none"))             .mappings(             m => m.fluentmappings.addfromassemblyof<nhibernatefactory>());         configuration ret = fc.buildconfiguration();         schemametadataupdater.quotetableandcolumns(ret);         return ret;       }  ...  public static void generatesql(mainwindowviewmodel viewmodel)     {         dialect requireddialect;         configuration cfg = buildnhconfig(viewmodel.connectionstring, viewmodel.dbtype.value, out requireddialect);          stringbuilder sqlbuilder = new stringbuilder();          foreach (string sqlline in cfg.generateschemacreationscript(requireddialect))             sqlbuilder.appendline(sqlline);          viewmodel.sql = sqlbuilder.tostring();     } 

explanation: when want set viewmodel's sql display on textbox (yea, wpf) initialize configuration programmatically connection string given in viewmodel , choose dialect/provider accordingly. when fluently configure nhibernate both set hbm2ddl.keywords (tried both auto-quote , keywords, being default) and, following this blog post, use schemametadataupdater.

the result i'm presented sql

create table `orderhistoryevent` (id bigint not null auto_increment, eventtype varchar(255) not null, eventtime datetime not null, entitytype varchar(255), comments varchar(255), order_id varchar(255), index integer, primary key (id)) 

where guilty index column not quoted.

the question is: given programmatic , fluent configuration of nhibernate, how tell nhibernate quote reserved word in sql exported generateschemacreationscript?

i have found workaround: when generate update script (the 1 runs hbm2ddl.auto=update) script correctly quoted.

the infamous index column has been discussed , findings it's hardcoded in fnh (tomanybase.cs, method public t aslist()).

since update script working creational script on empty database, changing code generate update script on empty db should equal generating creational script.

this happens because want generate script on own. there bug in nhibernate activates when call generateschemacreationscript , not when let sessionfactory build db you


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -