2009-07-19 136 views
3

我们正在为我们的ASP.NET应用程序使用ADO.NET实体。ADO.NET实体框架 - 预生成视图 -

我读过预先生成的视图提高了性能。提到博客文章,

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

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利用率变高。

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

我是否需要更新Web.Config或App.Config以将View类映射到某个位置?

请说明。

+0

检查哪个进程正在使用CPU。你的SQL Server在同一台机器上吗? – 2009-07-19 21:14:26

回答

5

我一直在想同样的事情,一直在挖一些东西。

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

即使视图是预编译的,它们只会生成ESQL,而不会运行实际的TSQL。然而,预编译视图确实允许查询的执行跳过验证和ESQL生成步骤,该步骤应该略微提高性能,特别是对于大型复杂查询。