Is it possible to create a database using NHibernate?

后端 未结 6 1392
一向
一向 2020-12-08 08:56

I am using NHibernate with FluentNHibernate for my DAL. I am also using SchemaExport and SchemaUpdate to create and update my database schema.

6条回答
  •  轮回少年
    2020-12-08 09:21

    Hmm, you can indeed use SchemaExport as you mention, but I see NHibernate primarely as a way to bridge the gap between OO domain model and a relational persistence storage. That is, for me NHibernate's purpose is to persist and retrieve entities in my domain model.

    When you want to do schema updates, imho, you should not use NHibernate (if possible at all), since that's not the purpose of NHibernate; there is a 'domain specific language' called SQL :) which is good at doing those things.

    In order to create my database, and update my database-schema, I use Migrator.NET, which is a framework which lets you write C# classes in where you specify what needs to be done (create a table, add a column, etc...).
    The advantage of this, is that Migrator.NET also supports multiple DBMS'es, so you do not end up writing DB-specific SQL code.

提交回复
热议问题