I am using EF 4.0 and in my entity data model I have several relationships where I have a 1-to-many associations and have the assocation flagged as Cascade OnDelete. Is there a way to programatically identify these associations for an entity type T?
One option I thought of was identifying these associations and in my T4 template annotate the navigation properties identifying that they are cascade delete. Of course, I would need to know how to identify if an association is flagged as Cascade Delete in my T4 template.
You can programatically discover more than you ever wanted to know about your entity model via the MetadataWorkspace class. The API is a bit of a challenge to figure out, however. Here is an example of how to discover relationships (via navigation properties) and their associated OnDelete setting:
Just FYI, I think the above code may identify the same relationship twice (once from each end).