我正在尝试将我们的本土ORM解决方案更改为EntityFramework 5的概念,我遇到的第一个问题似乎是一个严重的显示阻止。
EF5出现,我们的盒子,比ad hock sql执行标量sql操作需要大约9倍,但是当我查看生成的sql代码时,sql本身看起来写得相当好,并且运行得很快
我的C#代码:
int surveyId = (from survey in upsEntities.Surveys where !survey.Deleted select survey.SurveyID).First();
Debug.WriteLine("Loading surveyId : {0} through Linq took {1}ms using EF5", surveyId,
sw.Elapsed.TotalMilliseconds);
sw.Restart();
string sql = "Select top 1 surveyId from Survey where deleted = 0";
object val = SMSDataManager.Instance.DataAccessManager.ExecuteScalar(sql);
Debug.WriteLine("Loading surveyId : {0} through AdHock SQL took {1}ms using OrmDataManager", val,
sw.Elapsed.TotalMilliseconds);
SQL输出: EF5:
SELECT TOP (1)
[Extent1].[SurveyID] AS [SurveyID]
FROM [dbo].[Survey] AS [Extent1]
WHERE [Extent1].[Deleted] <> cast(1 as bit)
Adhock:Select top 1 surveyId from Survey where deleted = 0
加载surveyId:1到Linq使用EF5 2965.8625ms
加载surveyId:1到 AdHock SQL耗时384.8073ms
根据分析器,两者之间的持续时间对于EF5是1ms,对于ad hock是0ms。问题出现在EF5的审核注销事件,花费约3秒,我的广告文件sql需要~.6秒用于相同的注销事件。
是什么导致EF5的巨大开销,我该怎么做才能缓解或解释这个?
答案 0 :(得分:0)
每个应用程序域只进行一次初始化。根据模型的复杂程度以及首次连接数据库所需的时间,可能需要一些时间。您可以在我的博客上查看此评论,该评论简要讨论了初始化Entity Framework Code First View Generation Templates On Visual Studio Code Gallery - Comment #249。此页面:Performance Considerations for Entity Framework 5是您可能想要查看的内容。