[personal profile] finesoul

Source: http://blog.cincura.net/228787-make-your-entity-framework-model-faster-with-edmgen2/

If we’ll skip exact details, we can say, that internal behavior of whole modeling and mapping is based on views (attention, we’re not talking about views in i.e. SQL databases!). Mapping is compiled into bidirectional views. These views express entities in form of tables (one direction – so called query views) and tables in form of entities (other direction – so called update views). Among others these views satisfy entity = query_view(update_view(entity)). As you might expect, generating this views isn’t simple. More important, these views are generated in runtime. So if you have big model with a lot of associations and entities, the generating can take significant time. For my test, overgrown sort of , model with 400+ entities and 300+ associations it takes 20 seconds.

Luckily there’s a solution. These views can be generated using EdmGen or EdmGen2 (or your own tool). For this case I’ll use EdmGen2[4], because the work is slightly more comfortable, because you can work directly with EMDX file.

OK, so create model of your favorite database and create pre-build action in Visual Studio and add:
cd "$(ProjectDir)"
"$(SolutionDir)EdmGen2.exe" /ViewGen cs "$(ProjectDir)BigModel.edmx"


First row presets working directory to current project’s directory, because EdmGen2 doesn’t allows you to specify the name of output file (but you can change this, because sources are available). Next we’ll simply call EmdGen2 with /ViewGen parameter and specify language and path to EDMX file. After first compilation we’ve got file named .GeneratedViews.. Finally just add this file into your project and compile again.

If you’ll run the application, you might notice nice surprise – it’s faster. With my model the time has been shortened to 2 seconds. And of course, this depends on your model, but not bad for a simple smart calling of tool without any additional work. If you’re interested in overall cost of various processes in Entity Framework, read [1] or [2], maybe [3].

[1] http://blogs.msdn.com/adonet/archive/2008/02/04/exploring-the-performance-of-the-ado-net-entity-framework-part-1.aspx
[2] http://blogs.msdn.com/adonet/archive/2008/02/11/exploring-the-performance-of-the-ado-net-entity-framework-part-2.aspx
[3] http://blogs.msdn.com/adonet/archive/2008/03/27/ado-net-entity-framework-performance-comparison.aspx
[4] http://code.msdn.microsoft.com/EdmGen2
[5] http://msdn.microsoft.com/en-us/data/hh949853.aspx

P.S.
EdmGen on steroids? EdmGen2!

The EdmGen tool available in Entity Framework or simply SP1 installation is good tool for playing with CSDL, SSDL and MSL files. On the other hand, when using Visual Studio you get all these files in one EDMX file. Though it’s just a pack of these two files, you cannot use it as input/output for EdmGen.

Fortunately there’s a solution – EdmGen2. It’s simply EdmGen on steroids. EdmGen2 can read and write EDMX files and also translate between EDMX and CSDL, SSDL and MSL files. The source code is also available, so you can use sources as learning material to API in System.Data.Entity.Design.

Лютий 2022

Н П В С Ч П С
  12345
6789101112
13141516171819
202122232425 26
2728     

За стиль дякую

Створено з Dreamwidth Studios
Сторінка створена 2026-Лют-13, П'ятниця 03:12