When we created new records, the vehicle type field reverted to Not selected. This is because the insert method used the table type to determine the vehicle type field, which is correct yet unhelpful in this scenario.
First, we need to add a method to get the InstanceRelationType (the table ID of the table instance) from the vehicle type, open the code for the ConVMSVehicleTableType class, and add the following method:
public RefTableId GetInstanceRelationFromType(
ConVMSVehicleType _vehicleType)
{
RefTableId instanceType = tableNum(ConVMSVehicleTable);
switch (vehicleTable.InstanceRelationType)
{
case ConVMSVehicleType::Truck:
instanceType = tableNum(ConVMSVehicleTableTruck);
break;
case ConVMSVehicleType::Bike:
instanceType = tableNum(ConVMSVehicleTableBike);
break;
case ConVMSVehicleType::Car:
instanceType = tableNum(ConVMSVehicleTableCar);
break;
}
return instanceType;
}
This is the reverse of the method we wrote when we changed the vehicle table to use inheritance. The sample code that can be downloaded goes a little further by adding a delegate to handle vehicle types added by a customer or partner.
The next step would be to make the vehicle type field editable when using the entity. Open the designer for the ConVMSVehicleTableEntity data entity, and select the VehicleType field from the Fields list.
To complete the changes, you would then change the Allow edit on create property from Automatic to Yes. Then right-click on ConVMSVehicleTableEntity in the design and choose Update staging table. Whenever we make structural changes to the data entity, we must always update or regenerate the staging table.