简体   繁体   中英

Best Practice - How to extend the DB in a ServiceStack.OrmLite .NET project?

I recently took a .Net project over which exposes DAOs from a Microsoft SQL Database via ServiceStack REST API. The server runs on IIS 7.5

In the AppHost.Configure the complete database schema is created like so...

var dbFactory = new OrmLiteConnectionFactory(DI.DefaultConnectionString, SqlServerOrmLiteDialectProvider.Instance);
        using (var db = dbFactory.OpenDbConnection())
        {
            if (!db.TableExists(db.GetTableName<SomeSpecificDAO>())) //Create table if not exists
            {
                db.CreateTable<SomeSpecificDAO>();
                db.Insert(new SomeSpecificDAO { Data = 0, AnotherData = "", AnSoOne =  });
            }

        /// alot more tables follow....
        }

When I now want to extend a DAO (and therefore add a new column to a table for example) I would do this in Visual Studio, test it, and if it works I would remotely add the column via Microsoft SQL Server Management Studio on the live test server since I do not want to loose any data in the database. This is not very fast when having only one column to add, and it can be very cumbersome if there are more tables/columns added or fe the datatype of cells is changed.

What is the best practise in updating the database in Visual studio and on the test system? Is it even possible to have a "Code First approach" where I only extend the DAO and then update the databases?

查看ServiceStack 客户论坛中的这个现有线程,它解释了处理数据库架构更改的不同策略。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM