gpt4 book ai didi

c# - Entity Framework 性能缓慢

转载 作者:行者123 更新时间:2023-11-30 16:46:19 24 4
gpt4 key购买 nike

我们使用 EF 6.0、.NET 4.5 和代码优先方法,我们的数据库有大约 170 个实体(表),主表有大约 150,000 条记录 Entity Framework 的第一次加载大约需要 25 秒。这次我正在尝试改进,因为这太慢了,而且随着记录数量的增加,它变得更慢了。我曾尝试生成原生图像,尝试使用预生成的交互式 View ,但我无法取得任何重大改进。

谁能帮我解决这个问题?

谢谢。

最佳答案

您可以考虑 Entity Framework 预生成映射 View 。您可以使用EF Power Tools创建预生成 View 。

Using pre-generated views moves the cost of view generation from model loading (run time) to compile time. While this improves startup performance at runtime, you will still experience the pain of view generation while you are developing. There are several additional tricks that can help reduce the cost of view generation, both at compile time and run time.

enter image description here

您可以引用此以了解更多信息:Entity Framework Pre-Generated Mapping Views

您可以使用 Entity Framework 中的缓存来提高应用的性能。

有 3 种类型的缓存。

<强>1。对象缓存——内置于 ObjectContext 中的 ObjectStateManager 实例在内存中跟踪已被调用的对象 使用该实例检索。这也被称为一级 缓存。

<强>2。查询计划缓存 - 重用生成的存储命令 查询被执行了不止一次。

<强>3。元数据缓存 - 跨不同平台共享模型的元数据 连接到同一模型。

您可以引用这篇文章以了解更多信息:Performance Considerations for EF 6

关于c# - Entity Framework 性能缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40526018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com