code-第一或数据库首先,​​如何选择? [英] Code-First or Database-First, how to choose?

查看:177
本文介绍了code-第一或数据库首先,​​如何选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设,我们将开始新的项目 - 应用程序包含一些业务逻辑,对ASP.NET,WPF或两者的用户界面。我们想使用ORM或DAL code生成和实现业务逻辑的.NET类。有几个基本的方法我们如何能够EX preSS业务领域的思路:

Let us suppose we are going to start new project - application that contains some business logic, user interface on ASP.NET, WPF or both of them. We'd like to use ORM or DAL code generator and implement our business logic in .NET classes. There are several fundamental ways how we can express our ideas of business domain:

  • 实施基于.NET的商业类,让ORM生成相应的数据库架构
  • 在手动创建数据库模式,并生成.NET类由code发电机
  • 使用某种形式的可视化设计器,可以生成业务类和数据库结构或脚本

你这是什么preFER写:创建表的人(......)或公共类Person {...}
? 什么是这些方法的优点和缺点?
也许有一些特殊情况下的一种方法是比另一种更好?
如何选择一个特定项目的最佳方法是什么?

What do you prefer to write: "Create Table Persons ( ... )" or "public class Person { ... }"?
What are Pros and Cons of those ways?
Maybe there are some special situations where one way is better than another?
How to choose optimal way in a particular project?

我非常熟悉的code-第一(或模型一)的方式,但似乎大多数奥姆斯被设计为code发电机或映射器,即假设我将手动执行这两个数据库结构和业务类。

I am quite familiar with "Code-First" (or "Model-First") way, but it seems most of ORMs are designed as code generators or mappers, that suppose that I will manually implement both database structure and business classes.

根据经验性和ORM的例子答案是特别受欢迎的。

Answers based on expirience and examples of ORM's are especially welcome.

编辑:注意,这个问题是不是我应该怎么做第一次开始新项目时?,而是应该怎样手动声明/自动生成,领域类或数据库结构呢?

Note, the question is not "What should I do first when starting new project?", but "What should be manually declared / automatically generated, domain classes or database structure?"

推荐答案

我认为适当的方法进行系统的分析和设计开始​​,首先造型你的对象以及它们之间的关系。如果你正在创建一个图书馆系统,你应该想到的词组书,作者,出版社,ISBN为对象而不是数据库表或属性。我认为这是应该的方式。这已经说了,让我们承认,code发电机的方式节省了大量的时间,而那些需要一个关系型数据库,以便生成模型,并将其映射到数据库对象。我认为这是主要的原因,开发商往往先数据库有什么能证明我的观点更是code发电机开发商正努力扭转当前实施的操作(即您提供了一个商业模式,对象和类 - 和发电机与此相应的模式创建了DB)。

I think the appropriate approach to system analysis and design is to start by modeling your objects and the relations between them first. If you're creating a library system you should think of the phrases Book, Author, Publisher, ISBN as objects not as database tables or attributes. I believe this is the way it should be. That been said, let's admit that code generators save way a lot of time, and those require a relational database in order to generate the model and map it to the DB objects. I think this is the major reason why developers tend to start by the D.B. What could prove my point more is that code generators developers is trying hard to reverse the currently implemented operation (i.e. You provide a business model-objects and classes- and the generator creates the DB with the appropriate schema for this).

编辑:
这里是领域第一发电机的例子(ADO.NET实体框架本身) 模型优先


Here's an example of domain-first generators (ADO.NET Entity Framework itself) Model First :

Visual Studio 2010中具有的能力,以产生一个DDL并创建数据库来存储实体数据模型。开发人员完全控制整个流程能够自定义DDL,或选择他想要数据库,或微调映射过程。

Visual Studio 2010 has to ability to generate a DDL and create a database to store the entity data model. The developer has complete control over the entire process being able to customize the DDL, or to select the database he desires, or fine tune the mapping process.

这篇关于code-第一或数据库首先,​​如何选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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