实体关系设计 [英] Entity relationships design

查看:164
本文介绍了实体关系设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个更好的实体框架,代码优先或数据库优先?



为什么以及何时更好?



谢谢,

Which is better with Entity Framework , code first or database first ?

Why and when is it better?

Thank you,


推荐答案

当您想编写代码并生成反映该代码的数据库时,代码优先更好。当您想要自己设计数据库并让代码反映该数据库时,数据库首先会更好。因此,如果归结为您对数据库的特殊性以及您对其设计的重视程度。我认为大多数专业人员都会首先使用数据库,即使只是因为没有麻烦(当你先做代码并且你的代码发生变化时,你的数据库及其所有数据都会被破坏)。
Code first is better when you want to write code and have a database generated that reflects that code. Database first is better when you want to design the database yourself and have the code reflect that database. So if comes down to how particular you are about the database and how important you feel its design is. I think most professionals will go with database first, even if just for the lack of hassle (when you do code first and your code changes, your database and all its data is destroyed).


对于依赖高效数据库设计的大型项目:

(这是我写过的dbs的90%)



我推荐使用笔和纸:S



数据库设计的流程优势经历了几次规范化和反规范化的迭代。我发现在开始编写数据库之前组织我的db方式很有用。



然后我会先编写数据库。这有几个原因,但最好的原因是我只需拖放到dbml中。



我通常会一次执行一个表。就个人而言,我认为任何链接都不应该相互交叉,所以我这样做是为了证明我的情况。





I十多年来我一直在设计dbs,所以当我设计和实现它时,我可以在很大程度上直观地看到最终结果。您可能会发现首先从EF模型开始更容易,以便您可以更好地对其进行可视化,但我发现在数据库中进行调整和更改比从EF模型编辑它更容易和更快。



对于较小的dbs或查询和数据效率不是优先级

(例如基本内容网站或仅处理全局设置,例如)



好​​吧,无论什么方便。在设计上花费太多时间是不值得的。如果您知道需要哪些表格,那么您可以先轻松创建EF。



如果您可能编辑数据库,那么我会更多地转向数据库第一种方法,除非更改是次要的。





将一个小项目移交给大三学生时,最好采用EF第一种方法因为这对于访问你的来源的人来说很容易实现。





这只是恕我直言^ _ ^





编辑:更新了Sergeys的评论
For Larger projects that depend on an efficient db design:
(this is 90% of the dbs I have written)

I recommend pen and paper :S

The process good of DB design goes through several iterations of normalization and de-normalization. I find it useful to organize my db way before I start writing it.

I would then write the database first. There are several reasons for this but the best one is that I will just drag-drop into the dbml.

I will usually do that one table at a time. Personally, I don't think that any links should cross over each other, so I do this to prove my case.


I have been designing dbs for well over a decade so I can visualize the end result to a huge extent when I am designing and implementing it. You may find it easier to start with the EF model first so that you can visualize it better, but I find making tweaks and changes on the DB much easier and quicker that editing it from the EF models.

For smaller dbs or where query and data efficiency is not a priority
(such as basic content websites or just to handle global settings for eg)

Well, whatever is convenient. It isn't worth spending too much time on the design. If you know what tables are needed then you can easily create the EF first.

If you are likely to edit the database then I would swing more to the db first approach, unless changes are minor.


When handing over a small project to a junior, it would be best to have the EF first approach as this is easy to implement for anyone who accesses your source.


That's just IMHO ^_^


Updated with Sergeys comments in mind


这篇关于实体关系设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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