Retrieving entity metadata
When you create an Entity Framework context, you map a domain model to a data store. Specifically, in the case of relational databases, you assign the following:
Classes to tables
Properties to columns
References to foreign keys
Of course, in normal usage, you normally don't need to worry about these mappings; you just query the POCO domain model and that's it. But if you need to write SQL for more advanced queries, you are left with two options:
You know exactly the database names of all the tables and columns (keep in mind that the class
Person
can be mapped to, say,PERSON
,PEOPLE
,PERSON_DETAIL
,PERSON_DETAILS
, and so on)You obtain this information dynamically at runtime
If you want to be safe, you will stick to the second option and obtain all the information you need whenever you need it; this way, you know you're not wrong. That's what this chapter is about, after all!
Getting ready
We will be using the NuGet Package Manager to install the Entity Framework Core...