I have a TPH (Table per Hierarchy) set up in Entity Framework, where I use a column called Discriminator
to seperate the different EntityTypes.
I.e. when the Discriminator is 0 the type is Dog
, if it's 1 it's Cat
etc
Now I want to move some code for (mass)-updating from EF to a custom ExecuteSqlCommand
.
Question:
Is it possible to extract the Discriminator value from the Type through the MetadataWorkspace
or by some other way?
I'm look for something like GetDiscriminatorValue<Cat>("ColumnName")
If not possible: is there another way so I don't have to hardcode those values somewhere in my code?
Thanks,
I haven't tried yet but it seems that you can get the value (and other non-public properties) using reflection and MetadataWorkSpace. Take a look at this example: http://blog.cincura.net/231942-tph-mapping-discriminator-condition-from-metadataworkspace/