NHibernate和数据库更改/部署 [英] NHibernate and database changes/deployment

查看:140
本文介绍了NHibernate和数据库更改/部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在研究使用NHibernate和Fluent NHibernate来完成我的下一个项目,但是我想清楚的一件事情是如何管理对数据库的更改?例如,我有NH + FNH工作,应用程序已经部署并且正在运行,但是我们改变了开发环境,例如说我们为使用NH / FNH映射的实体添加一个新属性。



如何将这个改变应用到数据库而不必删除表?

谢谢
GE

解决方案

我有很好的使用这个框架的经验:

http://code.google.com/p/migratordotnet/



基本上,您可以为每个数据库更改创建一个类,并使用时间戳对类进行注释。然后按照时间戳顺序应用最终的程序集。

这意味着在开发过程中,每次签出后只需盲目运行数据库升级过程就变得容易了,并且知道你是与全球同步。

  using Migrator.Framework; 
使用System.Data;

namespace DBMigration
{
[Migration(20080401110402)]
public class CreateUserTable_001:Migration
{
public void Up()
$ b Database.CreateTable(User,
新列(UserId,DbType.Int32,
ColumnProperties.PrimaryKeyWithIdentity),
新列(Username DbType.AnsiString,25)
);


public void Down()
{
Database.RemoveTable(User);
}
}


I'm looking into using NHibernate and Fluent NHibernate for my next project but one thing I'd like clearing up before hand is how do you manage changes to the database?

eg, I have NH + FNH working, application has been deployed and is live but we make a change in the development environment, for example say we add a new property to a entity which is mapped using NH/FNH.

How do you apply that change to the database without having to drop the table?

Thank you GE

解决方案

I have very good experience using this framework:

http://code.google.com/p/migratordotnet/

Basically you create a class for each database change and annotate the class with a timestamp. The final assembly is then applied in timestamp order.

This means that during development it becomes easy after each checkout to just blindly run the db upgrade process, and know that you are synchronized with the world.

using Migrator.Framework;
using System.Data;

namespace DBMigration
{
    [Migration(20080401110402)]
    public class CreateUserTable_001 : Migration
    {
            public void Up()
            {
                    Database.CreateTable("User",
                            new Column("UserId", DbType.Int32,
                            ColumnProperties.PrimaryKeyWithIdentity),
                            new Column("Username", DbType.AnsiString, 25)
                            );
            }

            public void Down()
            {
                    Database.RemoveTable("User");
            }
    }

这篇关于NHibernate和数据库更改/部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆