I have two tables, binded by foreign key CarrierID:
Carrier[CarrierID,CarrierName]
CarrierID = 1, CarrierName = DHL
CarrierID = 2, CarrierName = Fedex
...
Vendo
I expect it is this combination:
// somewhere
comVendorCarrier.Text = vendor.Carrier.CarrierName.Trim();
...
// somewhere else
vendor.CarrierID = SelectedCarrierId;
One is using the object-oriented approach, one is using the id-based approach - however, if both are loaded and are incompatible, problems. I wonder if you should use:
vendor.Carrier = null;
vendor.CarrierID = SelectedCarrierId;
then there is exactly one definition of which carrier to use.
Alternatively, handle the carrier separately, for example, instead of:
comVendorCarrier.Text = vendor.Carrier.CarrierName.Trim();
use:
var carrier = context.Carriers.Single(x => x.Id = vendor.CarrierId);
comVendorCarrier.Text = carrier.CarrierName.Trim();
which then never loads vendor.Carrier
as an object.