When you create an entity instance object (e.g. new FamilyCar(); ) you can't switch the discriminator column anymore after that, because that would imply changing the type of the whole object, which isn't possible.
So you need a factory to create the instances based on the discriminator value. E.g. in your example, if the value is '2', the entity object to create is a FamilyCarEntity instance. However, you can't do:
- create a companycar entity instance,
- set the discriminatorcolumn
- and expect it to be a familycarentity instance
Because we're working with objects which have a fixed type.
So your dropdown's selection controls what entity is created AFTER selection. It doesn't control the entity which is already created. So there's no binding from combo to discriminator field, as it's not possible to set that field afterwards. (as I've explained above).
So, if you know the discriminator value, and you want to create the entity instance belonging to that discriminator value, you've to obtain the right factory for that discriminator column. You can use the same code path as the fetch logic does: use the root entity type's factory and call GetEntityFactory() on it by passing in an array of values and '0' as the index. the array of values is at least as wide as the # of fields in the root entity and place the discriminator value at the index of the discriminator field.
So say your root type CompanyCar has its discriminator field at index 3, and has 4 fields in total, you pass:
new object[] { null, null, 3, null};
and you'll get a factory back. You then call that factory's Create method and you'll get the entity of the right type. You can also use David's trick mentioned earlier or use a switch/case clause on your own.