Ah, I see, but would that allow me to get the table name as well as the count? I don't use Linq to Entities really.
My bigger point is that the metadata seems a bit locked down and hidden away which is a shame because it can be very useful.
I have just thought of another use case where the metadata would be useful:
I have plenty of reference data entities that are simple lookups - say an ID and a Description.
I am writing a maintenance form so the user can Add/Remove/Modify those Descriptions.
It is a generic form and used for many of these lookup entity types.
I would be helpful to know which of these lookups are currently 'in use'.
That way in the GUI, I can disable deletion of those rows rather than the suck-it-and-see method where I attempt to delete the user selection one at a time and ignore exceptions.
A Count of current usage would be even better since I can show the user that information - they may decide that if two Descriptions are nearly the same but one is only used once, they will change that one then get rid of the now unused Description.
Because these lookups can be used in multiple places, I would have to Count their usage on each related entity type. Future addition or removal of relations would then necessitate a code change. Failure to change the code accordingly could mean runtime failures.
That is where the Metadata would come in handy.
I should be able to write a helper method that takes an entity type, uses its relational meta data to determine which entities it is related to and sums up the Count of usage as its result.
Actually, internally it could fetch the IDs of the entity where the FK matches. I should then be able to write a helper method that says "Replace all occurrences of the PK for Description A with the PK for Description B then delete Description A"
The accounts package I am currently writing could also benefit from this. User wants to delete a used Nominal Account, they just choose another Nominal Account to use and all transactions get magically assigned to that other account.
So how about not making that metadata internal and/or providing some interfaces to make use of it with a bit of documentation?