我应该将 NHibernate SchemaExport 方法放在哪里?

发布于 2024-09-15 03:13:48 字数 227 浏览 3 评论 0原文

我应该将 NHibernate SchemaExport 方法放在哪里?当我决定重新创建数据库时应该如何调用它?

我应该将其保留在我的启动项目(asp.net mvc 项目)中吗?我应该创建一个单独的控制台项目只是为了导出我的架构吗?

我认为这些问题都源于这样一个事实:我不希望每次 Web 应用程序启动时都运行架构导出。

我正在使用 fluid nhibernate 如果这有什么区别的话。

Where should I put my NHibernate SchemaExport method and how should I call it when I decide to recreate the database?

Should I leave this in my startup project (an asp.net mvc project)? Should I create a seperate console project just for exporting my schema?

I think these questions all originate from the fact that I don't want schema export to run every time the web app starts.

I'm using fluent nhibernate if that makes a difference.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

提笔书几行 2024-09-22 03:13:48

我会将其分解为一个单独的程序集;然后,您可以从多个地方使用它(控制台应用程序、集成测试设置、安装程序等)。

I would factor this out into a seperate assembly; you could then use this from a variety of places (console app, integration test setup, installer, etc).

野侃 2024-09-22 03:13:48

作为一个想法:您可以将其放置在 ProjectInstaller 中,该安装程序可以选择接受命令行参数。因此,您不必为此而拥有额外的控制台应用程序。

As an idea: you could place it in a ProjectInstaller that optionally takes a command line argument. So you wouldn't have to have an extra console app just for that.

调妓 2024-09-22 03:13:48

我个人使用两个测试(在本例中使用 Nunit)来创建或更新数据库。在这两种情况下,我只生成脚本,因为我希望完全控制数据库的创建或更新时间。

    [Test]
    [Ignore]
    public void Create_Database_Schema_From_MappingFiles()
    {
        Configuration cfg = new Configuration();
        cfg.Configure();
        var schema = new SchemaExport(cfg);

        schema.Create(true, false);
    }

    [Test]
    [Ignore]
    public void Update_an_existing_database_schema()
    {
        Configuration cfg = new Configuration();
        cfg.Configure();
        var update = new SchemaUpdate(cfg);
        update.Execute(true, false);
    }

Personally I use two Tests (using Nunit in this case) to create or update the database. In both cases, I only generate the script, as I want full control as to when the database gets created or updated.

    [Test]
    [Ignore]
    public void Create_Database_Schema_From_MappingFiles()
    {
        Configuration cfg = new Configuration();
        cfg.Configure();
        var schema = new SchemaExport(cfg);

        schema.Create(true, false);
    }

    [Test]
    [Ignore]
    public void Update_an_existing_database_schema()
    {
        Configuration cfg = new Configuration();
        cfg.Configure();
        var update = new SchemaUpdate(cfg);
        update.Execute(true, false);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文