使用实体框架 4 时如何对数据库建模?
当我们使用 Entity Framework 4 作为 ORM 层时,尝试了解数据库建模的最佳方法。我们将使用 asp.net mvc 2 作为该应用程序。
是否值得尝试使用 Visual Studio 2010 附带的类图建模器进行建模,您可以在其中以图形方式将模型配置到 EDMX 文件中,然后生成数据库结构?
我遇到了一堆不平凡的问题,对于复杂的多对多映射或多主键实体,即使在使用工具研究了一段时间后,答案也不是那么明显。
我认为此时很容易放弃并开始使用真实的、有效的数据库建模工具对数据库进行建模,然后尝试从数据库生成 EDMX,而不是尝试采用模型优先方法。
Trying to wrap my head around the best approach in modelling a database when we are using Entity Framework 4 as the ORM layer. We are going to use asp.net mvc 2 for the application.
Is it worth trying to model using the class diagram modeller that comes with Visual Studio 2010 where you graphically configure your models into the EDMX file and then generate out the database structure?
I have run into a bunch of non trivial issues and for complex many to many mappings or multi primary key entities the answer is not that obvious even after poking around a while with the tools.
I figure its easy at this point to give up and start modelling the DB using real, working DB modelling tools and then try to generate out the EDMX from the database, rather than trying to do the model first approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这确实是一个偏好问题。如果您熟悉 SQL Server,那么这可能是最好的起点。但如果您更多的是 C# 程序员,有时更容易从 EDMX 设计器开始,创建模型,然后要求它弄清楚数据库应该是什么样子。
当然,如果您首先进行建模,您仍然需要进入 SSMS 并添加索引,并且可能根据您的喜好重命名一些 FK 和表。然后,您可以通过“模型更新”使模型恢复到最新状态。
建模继承也是您需要在设计器中执行的操作,但您也可以在 SSMS 或 EDMX 设计器中执行此操作。对于继承,我首先更喜欢 SQL,因为对于您想要什么形式的继承有明确的决定 - 每个层次结构、每个类或每个具体类型。
It's really a matter of preference. If you are comfortable in SQL server that's probably the best place to start. But if you are more of a C# programmer, it's sometimes easier to start in the EDMX designer, make the model and then ask it to figure out what the database should look like.
Of course if you do go model first you'll still need to go in to SSMS and add indexes and maybe rename some FKs and tables more to your liking. Then you can bring the model back up to date with an Update from Model.
Modelling inheritance is also something you'll need to do in the designer, but again you can either do it in SSMS or in the EDMX designer. For inheritance I mostly prefer SQL first because there is the explicit decision as to what form of inheritance you want - per hierarchy, per class, or per concrete type.