I have an abstract parent entity with 6 inherited child entities, using TPH in EF4.
Is there a simple way to get the value of the dicriminator column, bearing in mind that although at the moment it is the same as the Type.Name, this does not have to be the case.
In my case, I am importing data from many sources into a single table for processing – so the Disc is very useful so I only have one table, which I can expand to take in many sources.
I’d like to be able to simply loop through the collection and get the value of the discriminator – I would have thought that should be possible/sensible?
Discriminator column is represented by the type of the entity so you can use:
To get all SubtypeA instances in your TPH hierarchy or
To work with all entities and their types = discriminator values.
Discriminator cannot be mapped as a property so you cannot get its value directly without diving deep into
MetadataWorkspaceand traversing mapping at runtime – that would require some time spend in debugger to find a way for retrieving the mapped value. Still you will not be able to use discriminator column in LINQ queries or for inserting new entity via EF. It can be only useful for native SQL access.