ADO.NET Entity Framework - Pre-Generation of Views -

We use ADO.NET Entity for our ASP.NET application.

I read that pre-created views improve performance. Link to blog post,

http://blogs.msdn.com/adonet/archive/2008/06/20/how-to-use-a-t4-template-for-view-generation.aspx , I created the views. Namespace and classes created 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"; 

I added this to my data layer and tested the performance. Failed to see many improvements. CPU usage always goes up to 20-30% of use (response time is good) and decreases to 0% in 500 ms - 1 sec. I think the CPU usage is getting high due to the generation of the view every time.

I could not understand how the entity infrastructure knows that this is my pre-generated view class for my model, although the MyModel.edmx and MyModel.Views.cs files match the file name.

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

Please clarify.

+3
source share
1 answer

I was wondering the same thing and doing digging.

As far as I can tell, the generated class file contains an assembly level attribute, EntityViewGenerationAttribute , which defines the type of class that contains the precompiled view. Then, and here, only making reasonable assumptions, during compilation, the class must be loaded through reflection and somehow connected with the requests that the view defines. Perhaps in the ESQL cache, which will make some sense.

Although the view is precompiled, they only produce ESQL, not the actual TSQL that will be launched. However, preliminary compilation of views allows you to execute a query to skip the validation phase and ESQL, which should provide a slight performance boost, especially for large compiled queries.

+5
source

Source: https://habr.com/ru/post/978852/


All Articles