Entity Framework initialization is SLOW — what can I do to bootstrap it faster?

后端 未结 3 1264
滥情空心
滥情空心 2020-11-30 02:13

My EF 4.3.1 model has 200-odd tables. Initial startup is horrible, several minutes. A DotTrace-captured profile implies some terrible algorithm/scalability choices deep in

3条回答
  •  既然无缘
    2020-11-30 02:28

    In pre EF6 view generation is known to be slow for bigger models. For now the solution is to use pregenerated views. This way you generate views at design time and are avoiding this work at runtime. To do that download EF power tools and select "Optimize Entity Data Model". It will add a C# file to your project that contains views. The down side is that you will need to do it each time your model changes. Note: to generate views with the tool it will take about the same amount of time it takes to generate views at runtime (so sometimes you need to be patient). Here is a post about EF Power Tools that might be helpful: http://blogs.msdn.com/b/adonet/archive/2011/05/18/ef-power-tools-ctp1-released.aspx

    Edit

    Recently I created a different solution that is much more convenient to use (note it only works on EF6) - http://blog.3d-logic.com/2013/12/14/using-pre-generated-views-without-having-to-pre-generate-views-ef6/

提交回复
热议问题