Not necessarily will that be an answer, but maybe it’ll help you!
Settings
Some questions about your settings:
- How you are setting up the Nhibernate session?
- Is using which Schema?
SchemaUpdate
? SchemaExport
?
- Nhibernate is creating their tables?
Basically these settings tell if Nhibernate will compare the metadata of its tables with its Mapping, and if it will create some DDL(Data Definition Language) in the database (This impacts directly on the first connection).
I can demonstrate 3 configuration scenarios to compare with your settings:
new SchemaExport(cfg).Create(false, true); // apagar o database e criar novamente todas as tabelas
(recommended only for use in tests, as the data/tables will be deleted every new connection, NEVER in production);
new SchemaUpdate(cfg).Execute(false, true); // atualizar o database, acrescentando novas tabelas e colunas sem excluir o que não está no mapeamento
(recommended for use in testing, and in the development phase while modelling the tables, NEVER in production, as it will compare the database media with the mapping and add the Ddls that are not in the database);
new SchemaExport(cfg).Create(false, false); // normal, não criar nenhum DDL no database
(Recommended, for any stage of development, if you do not want Nhibernate to change its database structure, and this setting does not compare metadata and does not create any DDL when creating the connection, MUST be used in production, because it is the configuration that has least overflow at startup).
About booting Nhibernate when booting the system!
You can initialize the Nhibernate connection at any time by running any routine in the database (query, Insert, etc).
You can simply in the Home Controller make a simple query to initialize Nhibernate. Or you can do this at system startup, such as at Application_Start()
in the Globa.asax.cs
in the case of ASP.NET < 5, or Startup.cs
on ASP.NET 5.
Which database are you using? Is this slowness in any "first" query? Could you post your
query
in the question?– Randrade
I am using SQL Server. Not necessarily query. If the first thing, with access to base, that I do on the site is the inclusion of the product then the inclusion that will take.
– Vitor Ferreira