ADO.NET 实体框架 - 预生成视图 - [英] ADO.NET Entity Framework - Pre-Generate Views -

查看:21
本文介绍了ADO.NET 实体框架 - 预生成视图 -的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We are using ADO.NET Entity for our ASP.NET application.

我了解到预生成的视图提高了性能.参考博文,

I have read that the pre-generated views improves the performance. Referred to the blog post,

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

http://blogs.msdn.com/adonet/archive/2008/06/20/how-to-use-a-t4-template-for-view-generation.aspx, I generated the views. The namespace & classes generated as

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 利用率会很高.

I added this to my data layer and test the performance. Couldn't see much improvement. CPU usage always goes to 20-30% utilization (response timing is good) and reduce back to 0% in 500ms - 1 sec. I think the CPU utilization goes high because of view generation every time.

我无法理解实体框架如何知道这是我为我的模型预先生成的视图类,尽管 MyModel.edmx &MyModel.Views.cs 与文件名匹配.

I couldn't understand how the entity framework knows that this is my pre-generated view class for my model eventhough the MyModel.edmx & MyModel.Views.cs matches with filename.

我是否应该更新 Web.Config 或 App.Config 以将 View 类映射到某个地方的模型?

Should I have to update Web.Config or App.Config to map the View class to model somewhere?

请澄清.

推荐答案

我一直在想同样的事情,一直在做一些挖掘.

I've been wondering the same thing and been doing some digging.

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

As far as I can tell the generated class file contains an assembly level attribute, EntityViewGenerationAttribute, which defines the class type that contains the pre-compiled view. Then, and here im only making educated guesses, at compile time the class must be loaded via reflection and in some way bound to the queries the view defines. Possibly in the ESQL cache, which would makea certain amount of sense.

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

Even though the view's are pre-compiled they only produce ESQL, not the actual TSQL which will be ran. However pre-compiling views does allow the execution of a query to skip the validation and ESQL generation step which should offer a slight performance gain, especially for large compilcated queries.

这篇关于ADO.NET 实体框架 - 预生成视图 -的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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