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 ...
Get Entity Framework Core Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.