Search code examples
nhibernateormfluent-nhibernatedatabase-metadata

How do you check if a table exists with NHibernate(or Fluent)?


Whats the best, most consistent way to check if a table exists in NHibernate (or with Fluent-NHibernate)?

Is it even possible? I mean it seems like a simple task for such a heavy-duty ORM.

Also on a related question, can you check if a set of tables or a whole schema exists with NHibernate?


Solution

  • If you store you NHibernate configuration somewhere or do it before you build your session factory it is possible to validate the generated schema against the database.

        public void ValidateSchema(Configuration config)
        {
            new SchemaValidator(config).Validate();
        }