code第一种方法与数据库第一种方法 [英] Code first approach versus database first approach

查看:78
本文介绍了code第一种方法与数据库第一种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个asp.net MVC 3 web应用程序,我第一次使用的数据库,但我已经使用实体框架映射数据库表到实体类以后,我与这些表进行交互,因为我将在进行交互code。通过处理数据库表作为一个类的对象第一种方法。

I am working on an asp.net MVC 3 web application and I am using database first, but after I have mapped the DB tables into entity classes using entity framework, I am interacting with these tables as I will be interacting on the code first approach by dealing with Database tables as classes an objects.

所以映射表到实体类后,我发现,code第一种方法和DB首先非常相似,但是除了开始从头开始编写实体类(如code第一次)我已经创建了实体类从现有的数据库表 - 这是在我的情况更容易,更方便。

So after mapping the tables into entity classes I find that the code first approach and DB first are very similar but except of start writing the entities classes from scratch (as in code first) I have created the entity classes from existing database tables - which is easier and more convenient in my case.

那么,有没有,除非我正在使用一种方法比其他现在直到我无法找到任何我不能做一些功能上的哪些具体案例?

推荐答案

已经处理了使用DB-1 EDMX pre EF 4.1很多很多头疼,我偏code-第一。但我不会去传福音吧。

Having dealt with many many headaches using db-1st EDMX pre EF 4.1, I am partial to code-first. But I'm not going to evangelize it.

在除了直接存储过程映射&放大器;在帕维尔的应答和涉及功能,导入功能;发表评论,您将无法更改命名空间或任何其他code在生成的文件,当您使用DB-第一。据我所知所有的文件嵌套在.TT下的文件。如果将其移动到逻辑文件夹和放大器的方法;在你的项目的命名空间,那么我没有意识到这一点。

In addition to the direct sproc mapping & function import features mentioned in Pawel's answer & comment, you won't be able to change the namespaces or any other code in the generated files when you use db-first. Afaik all of the files are nested under the .tt file. If there is a way to move them into logical folders & namespaces in your project, then I'm not aware of it.

此外,如果你想你的DbContext从实体分隔成一个单独的项目,我记得这是可能的pre-EF 4.1。但它更麻烦,因为你必须运行在每个数据库更改后两者.TT文件的自定义工具。随着code-第一,这是pretty简单,因为你处理的纯面向对象的。

Also if you ever want to separate your DbContext into a separate project from your entities, I recall this was possible pre-EF 4.1. But it was more cumbersome, because you had to run custom tool on both .tt files after each db change. With code-first this is pretty straightforward because you're dealing with pure OOP.

这篇关于code第一种方法与数据库第一种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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