实体框架4.1大量表(715) [英] Entity Framework 4.1 for large number of tables (715)

查看:101
本文介绍了实体框架4.1大量表(715)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为具有700多个表的数据库开发数据访问层。我创建的模型包括所有的表,这产生了一个巨大的模型。然后,我将模型改为使用4.1中的DBContext,这似乎改进了它如何编译和工作。设计师似乎没有工作。

I'm developing a data access layer for a database with over 700 tables. I created the model including all the tables, which generated a huge model. I then changed the model to use DBContext from 4.1 which seemed to improve how it compiled and worked. The designer didnt seem to work at all.

然后,我创建了一个测试应用程序,它刚刚在表中添加了两个记录,但处理器在db.SaveChanges中为100%方法。作为一个黑盒子,很难确定出了什么问题。

I then created a test app which just added two records to the table, but the processor went 100% in the db.SaveChanges method. Being a black box it was difficult to accertain what went wrong.

所以我的问题是



  1. 实体框架是大型数据库的最佳方法

  2. 如果是,应该将模型分解为逻辑区域。我确实注意到,您在多个模型中不能拥有相同的sql表。

  3. 我已经看到,在这些大的情况下,代码唯一的方法是最好的。这是什么?


任何指导将真正感谢

谢谢

推荐答案

大数据库总是特别的。任何技术在使用大型数据库时都有一些利弊。

Large database is always something special. Any technology has some pros and cons when working with a large database.

您遇到的问题最可能与建立模型有关。当您首次启动应用程序并使用EF相关内容时,EF必须构建模型描述并进行编译 - 这是您可以在EF中找到最耗时的操作。该操作的复杂性随模型中的实体数量而增加。一旦模型被编译,它将在应用程序的整个生命周期中重复使用(如果重新启动应用程序或卸载应用程序域,则必须再次编译模型)。您可以通过预编译模型来避免这种情况。这是在设计时完成的,您可以使用一些工具从模型生成代码,并将该代码包含在项目中(必须在模型中每次更改后再次完成)。对于基于EDMX的模型,您可以使用 EdmGen.exe 生成视图和基于代码的模型可以使用 EF Power Tools CTP1

The problem you have encountered is the most probably related to building the model. When you start the application and use EF related stuff for the first time EF must build the model description and compile it - this is the most time consuming operation you can find in EF. Complexity of this operation grows with number of entities in the model. Once the model is compiled it is reused for the whole lifetime of the application (if you restart the application or unload application domain the model must be compiled again). You can avoid this by precompiling the model. It is done at design time where you use some tool to generate code from the model and you include that code into your project (it must be done again after each change in the model). For EDMX based models you can use EdmGen.exe to generate views and for code first based models you can use EF Power Tools CTP1.

EDMX(设计师)在VS 2010 SP1中得到改进,以便能够使用大型机型,但我仍然认为在这种情况下,大部分是大约100个实体/表。在同一时间,你很少需要715个表格在同一个模型。我相信这些715表确实模拟了几个领域,所以你可以将它们分成多个模型。

EDMX (the designer) was improved in VS 2010 SP1 to be able to work with large models but I still think the large in this case is around 100 entities / tables. In the same time you rarely need 715 tables in the same model. I believe that these 715 tables indeed model several domains so you can divide them into multiple models.

当您使用DbContext和代码优先时,也是如此。如果你建立一个类,你认为这是正确的设计,当类暴露715属性?我不这么认为,但这正是您导出的 DbContext 看起来像 - 它具有每个暴露的实体集的公共属性(在最简单的映射中,它意味着一个属性表)。

The same is true when you are using DbContext and code first. If you model a class do you think that it is correct design when the class exposes 715 properties? I don't think so but that is exactly what your derived DbContext looks like - it has a public property for each exposed entity set (in the simplest mapping it means one property per table).

相同的实体可以在多个模型中使用,但是您应该尽可能多地避免它,因为在一个上下文类型中加载实体并使用它时可能会引入一些复杂性在其他上下文类型中。

Same entity can be used in multiple models but you should try to avoid it as much as possible because it can introduce some complexities when loading entity in one context type and using it in other context type.

仅代码=代码第一=当您在代码中定义映射而不使用EDMX时,实体框架。

Code only = code first = Entity framework when you define mapping in the code without using EDMX.

这篇关于实体框架4.1大量表(715)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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