My application allows the user to create products along with their UOM (Units of Measurement) and Barcodes During the creation process, API will check if there is no barcode
When the BeforeSaveEntity
and BeforeSaveEntities
methods are called, the entities have just been materialized from the JSON stream. They haven't been added to the EF context yet. Their data properties are all populated, but their navigation properties are not. So the relationships that you need are not yet available.
If the related entities (Barcode and Unit and Product, in your case) are in the same change set, you will need to use BeforeSaveEntities
(which gives you access to the full saveMap
) and find the related entities in the saveMap
manually (i.e. find them by type and by key).
If the related entities you need are not in the saveMap
, you will need to find them from the data store. In EF you would do that by creating a new EF Context, as Ward described in his answer.