.Henrik


31. okt 2009 20:40

The Entity Framework designer gets a lot of criticism because it is buggy, doesn’t scale too well when the number of database tables increase and because it does not support all of the features of the Entity Framework.

We use and like the Entity Framework but we have dumped the Entity Framework designer long time ago.

When using the Entity Framework you have to have an EDM (Entity Data Model) description consisting of three parts: A storage model, an entity model and a mapping between the two. The EDM is XML based and is defined by either a single XML file with three parts or three separate files.

Furthermore you need a set of classes matching the entity model described by the EDM.

When using the Entity Framework designer both the EDM and the classes are automatically generated. Alternatively the EDM and the classes can be generated by using either the command line edmgen tool or the functionality defined in the System.Data.Entity.Design namespace defined in the component of the same name.

Instead of using the Entity Framework designer we have used the functionality in the System.Data.Entity.Design namespace for implementing our own simple command line tool (called EdmModifier) for generating both EDM files and classes.

EdmModifier reads a specified XML file containing instructions for generating EDM and code files as well as instructions for modifying the generated files.

Snippet from an EdmModifier specification file.
Above: Snippet from an EdmModifier specification file.


If needed multiple EdmModifier specification files can be combined and executed one after another - could be beneficial if the development team and/or the the number of tables is large.

The tool does the following:

1)      EdmModifier reads the XML based specification file.

2)      It uses functionality in the System.Data.Entity.Design namespace for generating an EDM consisting of three XML files corresponding to each of the three parts of the EDM.

3)      It modifies the EDM files (renaming entities, associations, changing cardinalities, …).

4)      It uses functionality in the System.Data.Entity.Design namespace for generating classes based on the EDM specification.

By defining the changes we want to apply to the EDM in a separate file instead of editing directly in the EDM, we gain the same basic advantages that a developer gains, when defining changes to classes generated by Visual Studio in a partial class instead of directly in the generated code.

By using EdmModifier

  • we avoid the flaws of the Entity Framework designer
  • we speed up generating the EDM
  • we avoid editing directly in the EDM file(s)
  • we can regenerate the EDM without losing our modifications
  • we can - if needed - specify our own abstractions that makes it simple to define functionality that is complex to define in the EDM.
  • we can use EdmModifier as part a build process

If you do not like the Entity Framework designer do not take it out on the Entity Framework – just avoid the designer. The designer is by no means neither necessary nor sufficient for efficiently working with the Entity Framework anyway.



Abonnér på mit RSS feed.   Læs også de øvrige indlæg i denne Blog.