简体   繁体   English

ORM代码优先,生产数据库优先

[英]ORM Code First versa Database First in Production


I have been using SQL since 1985, so am very comfortable with DB servers. 自1985年以来我一直在使用SQL,因此对DB服务器非常满意。
I see (C#) Code First as yet another fad, that comes and goes. 我认为(C#)Code First是又一时的风尚。 It seems to suit people that have no DBA background. 似乎适合没有DBA背景的人。 Equally if using Code First and you have not idea what DB you are connecting to eg it might be Mongo later that too is a useful abstraction. 同样,如果使用Code First,但您不知道要连接到哪个DB,例如稍后可能是Mongo,这也是有用的抽象。 Code First does not let itself to Database Diagrams so you can see what is going on. Code First不允许自己进入数据库图,因此您可以查看发生了什么。
I would like to know how you promote changes into a production SQL server using code first, where you have no desire to Drop and recreate the DB, unlike using an ALTER TABLE command. 我想知道如何首先使用代码将更改促进到生产SQL Server中,在这种情况下,您不希望删除和重新创建数据库,这与使用ALTER TABLE命令不同。 I have used tools from Red-Gate that make DB code promotions easy. 我使用了Red-Gate的工具,这些工具使DB代码升级变得容易。 So why Code First? 那为什么要先编码呢? How do you move DB Changes into production? 您如何将DB Changes投入生产?

The code first approach is something that is really nice to have when you're prototyping applications and "don't care" about the "persistence layer" too much in the beginning. 当您对应用程序进行原型设计并且一开始就不太在意“持久层”时,采用代码优先的方法确实非常好。 It helps getting quick results in a time when things are not at all well defined yet, because you can always very easily drop and re-create your database of your greenfield project. 当您还没有很好地定义事物时,它可以帮助您快速获得结果,因为您始终可以非常轻松地删除并重新创建未开发项目的数据库。

Unfortunately, most tools that offer this approach do not really help transitioning from the "greenfield project mode" to the more longterm "legacy project mode" where database migrations are essential. 不幸的是,大多数提供这种方法的工具并不能真正帮助从“未开发项目模式”过渡到对数据库迁移至关重要的更长期的“遗留项目模式” In fact, not only are database migrations difficult to achieve in "client model first" approaches, but more importantly, the likelihood of the database model not being well designed is quite high. 实际上,不仅在“客户端模型优先”方法中很难实现数据库迁移,而且更重要的是,数据库模型设计不当的可能性非常高。

Developers pay a high price for the quick win - as always. 与往常一样,开发人员为快速获胜付出了高昂的代价。 It is really not a good idea and a lot of more experienced developers who are used to working with legacy, do agree with you: Go database first, and derive your client (eg ORM) models from it. 这确实不是一个好主意,并且许多经验丰富的开发人员习惯于处理遗留问题,并同意您的观点:首先进入数据库,并从中获得客户(例如ORM)模型。

I have written about this topic here, including the advantage of using client model source code generation . 我在这里已经写过有关此主题的文章,包括使用客户端模型源代码生成的优势

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

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