gpt4 book ai didi

entity-framework - ADO.NET Entity Framework - 预生成 View -

转载 作者:行者123 更新时间:2023-12-01 12:01:16 25 4
gpt4 key购买 nike

我们正在为我们的 ASP.NET 应用程序使用 ADO.NET 实体。

我了解到预生成的 View 可以提高性能。引用博文,

http://blogs.msdn.com/adonet/archive/2008/06/20/how-to-use-a-t4-template-for-view-generation.aspx ,我生成了 View 。命名空间和类生成为

namespace Edm_EntityMappingGeneratedViews
{


/// <Summary>
/// The type contains views for EntitySets and AssociationSets that were generated at design time.
/// </Summary>
public sealed class ViewsForBaseEntitySets4D4A6E0AA7AF6B2298FABB4F22235831 : System.Data.Mapping.EntityViewContainer
{

/// <Summary>
/// The constructor stores the views for the extents and also the hash values generated based on the metadata and mapping closure and views
/// </Summary>
public ViewsForBaseEntitySets4D4A6E0AA7AF6B2298FABB4F22235831()
{
this.EdmEntityContainerName = "JSEntities";

我将其添加到我的数据层并测试了性能。看不到太大的改善。 CPU 使用率总是达到 20-30% 利用率(响应时间很好)并在 500 毫秒 - 1 秒内降低回 0%。我认为 CPU 利用率升高是因为每次都生成 View 。

我无法理解 Entity Framework 如何知道这是我为我的模型预先生成的 View 类,即使 MyModel.edmx 和 MyModel.Views.cs 与文件名匹配。

我是否必须更新 Web.Config 或 App.Config 才能将 View 类映射到某处的模型?

请澄清。

最佳答案

我一直在想同样的事情并且一直在做一些挖掘。

据我所知,生成的类文件包含一个程序集级属性 EntityViewGenerationAttribute,它定义了包含预编译 View 的类类型。然后,这里我只是做出有根据的猜测,在编译时必须通过反射加载类,并以某种方式绑定(bind)到 View 定义的查询。可能在 ESQL 缓存中,这在一定程度上是有意义的。

即使 View 是预编译的,它们也只生成 ESQL,而不是将要运行的实际 TSQL。然而,预编译 View 确实允许查询的执行跳过验证和 ESQL 生成步骤,这应该会带来轻微的性能提升,尤其是对于大型复杂查询。

关于entity-framework - ADO.NET Entity Framework - 预生成 View -,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1149290/

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