Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 使用实体框架获取整个数据库是否正常?_Performance_Entity Framework - Fatal编程技术网

Performance 使用实体框架获取整个数据库是否正常?

Performance 使用实体框架获取整个数据库是否正常?,performance,entity-framework,Performance,Entity Framework,在我们正在开发的应用程序中,我们有以下代码 EntityContext entity = TransactionManager.GetEntityContext(); int idType = entity.InfoSectnGess.Where(e => e.NoSeqInfoSecGes == noSeqInfoSecGes).Single().NoSeqTypeInfo; return entity.ListValues.Where(e

在我们正在开发的应用程序中,我们有以下代码

        EntityContext entity = TransactionManager.GetEntityContext();
        int idType = entity.InfoSectnGess.Where(e => e.NoSeqInfoSecGes == noSeqInfoSecGes).Single().NoSeqTypeInfo;
        return entity.ListValues.Where(e => e.NoSeqTypeInfo == idType && e.NoSeqChoixValeur == noSeq).Single().DescChoixValeur;
EntityContext基于System.Data.Objects.ObjectContext

当我运行调试器时,在第一行放置一个断点,然后查看entity包含的内容,我看到它包含数据库中的所有“表”(entity字段),但它们都是空的(null)

如果我进入下一步,那么我的“表格”中充满了。。。好。。。整个数据库

当然,我关心的是表演

这个解决方案是可行的还是会随着时间的推移变得太慢


我问了一个支持这个想法的人,他告诉我不会有这样的麻烦。然而,当我看到entity.InfoSectnGess包含380个元素(dev的临时数据)并且它将很快包含数千条(如果不是数百万条)记录时,我不禁怀疑。。。哪里有魔力?EF不是这样工作的。发布GetEntityContext()方法的代码。如果您的ObjectContext启用了延迟加载,则在Visual Studio中调试时,只要按住shift+F9键,它就会立即带来数据。正常运行应用程序时不会发生这种情况。然后,如果您需要数据库中的1条记录,请使用
FirstOrDefault
First
,如果您确定它总是在那里,而不是
Where()
和之后的
。Single()