Chapter 12. Exploring EDM metadata

 

This chapter covers

  • Reading the EDM
  • Retrieving entity structures
  • Retrieving function structures
  • Writing generic code

Roughly speaking, the EDM consists of three XML files carrying information about classes, database, and their mappings. It’s no surprise that Entity Framework is the first consumer of these XML files, using them to generate the SQL code for CRUD operations, to understand whether a column is an identity on the database, and much more.

Reading XML files with LINQ to XML is easier than ever, but it will never be like having a set of well-designed APIs that access the same data. Entity Framework’s regular need to access EDM metadata led to the need for simplicity, which in turn led to a set of APIs. At the beginning, the APIs were for internal use only, but they were later made public so that everyone could access them.

Metadata retrieval introduces the possibility of writing generic code. By generic, we mean code that works with entities without even knowing what type the entities are. For instance, you could write a clever extension method that takes an entity and decides whether to perform an AddObject or an Attach based on the key value, as we described in chapter 6.

12.1. Metadata basics

12.2. Retrieving metadata

12.3. Building a metadata explorer

12.4. Writing generic code with metadata

12.5. Summary