实体框架 - 初始保存缓慢 [英] Entity Framework - Initial Save is slow

查看:154
本文介绍了实体框架 - 初始保存缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在实施一个使用EF4和WPF的系统。我们注意到初始保存数据的一个问题:当运行初始的SaveChanges时,在运行context.SaveChanges()命令时,延迟4到6秒。每个后续SaveChanges都很快,没有明显的延迟。这不是一个重大问题 - 但是一个烦恼是无所事事的。



有没有人经历过这个问题,知道一个方法?



谢谢

解决方案

问题解决:生成模型的视图。其原因及其解决方法如下: http:// msdn.microsoft.com/en-us/library/bb896240.aspx



简而言之,每次创建一个新的上下文实体框架生成一组用于访问数据库的视图。这种视图生成是一项昂贵的操作,并且解释了所遇到的重要的初始延迟。通过预先考虑这些观点,避免了这种初始延迟。


We are implementing a system using EF4 and WPF. We are noticing an issue with the initial saving of data: when the initial SaveChanges is run there is a 4 to 6 second delay when context.SaveChanges() command is run. Every subsequent SaveChanges is very fast with no noticable delay. This is not a major issue - but an annoyance none-the-less.

Has anyone out there experienced this issue and know a way around it?

Thanks

解决方案

Problem solved: the answer was to pre-generate the model's views. The reason for this and method to implement the solution is found here: http://msdn.microsoft.com/en-us/library/bb896240.aspx.

In short - everytime a new context is created Entity Framework generates a set of views used to access the database. This view generation is an expensive operation and accounts for the significant initial delay encountered. By precomiling these views this initial delay is avoided.

这篇关于实体框架 - 初始保存缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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