简体   繁体   English

最佳实践 - 如何在 ServiceStack.OrmLite .NET 项目中扩展数据库?

[英]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.我最近接受了一个 .Net 项目,该项目通过 ServiceStack REST API 从 Microsoft SQL 数据库公开DAOs The server runs on IIS 7.5服务器在 IIS 7.5 上运行

In the AppHost.Configure the complete database schema is created like so...AppHost.Configure ,完整的数据库架构是这样创建的......

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.当我现在想要扩展DAO (例如,因此向表中添加一个新列)时,我会在 Visual Studio 中执行此操作,对其进行测试,如果可行,我将通过 Microsoft SQL Server Management Studio 远程添加该列实时测试服务器,因为我不想丢失数据库中的任何数据。 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?在 Visual Studio 和测试系统上更新数据库的最佳实践是什么? Is it even possible to have a "Code First approach" where I only extend the DAO and then update the databases?甚至有可能采用“代码优先方法”,我只扩展DAO然后更新数据库?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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