Improve Query Performance

How to: Pre-Generate Views to Improve Query Performance (Entity Framework)

To generate model and mapping files for the School model in the output directory

  1. In Solution Explorer, double-click the School.edmx file.

This displays the School model in the Entity Designer.

  1. In the Model Browser, select the SchoolModel model and change Metadata Artifact Processing to Copy to Output Directory.

This ensures that the model and mapping files are generated in the output directory.

  1. Build the solution.

This generates the model and mapping files in the output directory.

To add view generation to a C# project

  1. In Solution Explorer, select the project for which you want to specify the build event.
  2. On the Project menu, click Properties.
  3. Select the Build Events tab.
  4. In the Pre-build Event Command Line window, add the following pre-build event, without line breaks:

Copy

 "%windir%\Microsoft.NET\Framework\v3.5\EdmGen.exe" /nologo /language:CSharp /mode:ViewGeneration "/inssdl:$(TargetDir)DDC.ssdl" "/incsdl:$(TargetDir)DDC.csdl" "/inmsl:$(TargetDir)DDC.msl" "/outviews:$(ProjectDir)DDC.Views.cs"

  1. Build the solution.

This generates the view file School.Views.cs.

  1. In Solution Explorer, right-click the project name and select Add Existing Item.

The Add Existing Item dialog box appears.

  1. Navigate to the project's root folder and select the School.Views.cs file.
  2. Click Add.
  3. Build the solution.

To re-add mapping and model files as embedded resources for ASP.NET projects

  1. On the Project menu, click Add Existing Item.
  2. Browse to the output directory for the project, select School.csdl, and then click OK.
  3. In Solution Explorer, select the added file.
  4. In Properties, set Build Action to Embedded Resource.
  5. Repeat steps 1 through 3 for the School.ssdl file and the School.msl file.
  6. In Solution Explorer, double-click the App.config file and then modify the Metadata parameter in the connectionString attribute based on one of the following formats:
  • Metadata= res://<assemblyFullName>/<resourceName>;
  • Metadata= res://*/<resourceName>;
  • Metadata=res://*;

The resourceName may include the project namespace. For more information, see Connection Strings (Entity Framework).

 

 

 

 

DDC

1

1.         In  DDC Project Solution Explorer, select the project   for which you want to specify the build event.

2.         On the Project menu, click Properties.

3.         Select the Build Events tab.

4.         In the Pre-build Event Command Line window, add the   following pre-build event, without line breaks:

Copy

 "%windir%\Microsoft.NET\Framework\v3.5\EdmGen.exe"   /nologo /language:CSharp /mode:ViewGeneration   "/inssdl:$(TargetDir)DDC.ssdl"   "/incsdl:$(TargetDir)DDC.csdl"   "/inmsl:$(TargetDir)DDC.msl"   "/outviews:$(ProjectDir)DDC.Views.cs"

 

5.         Copy all files in ...\Release\DAL\Model\  to ...\Release . And Then Build the   solution                                                                       .   This generates the view file DDC.Views.cs

6.         In DDC Project Solution   Explorer, right-click the project name and select Add                        Existing Item.The Add   Existing Item dialog box appears.

7.         Navigate to the project's root folder and select the DDC.Views.cs   file.

8.         Click Add.

9.         Build the solution.     

10.      When Build , display window as follow,   and then click “Yes to ALL”

          

   

 

posted @ 2016-06-23 18:12  光阴的故事-SKY  阅读(151)  评论(0编辑  收藏  举报