In your xpath when retrieving entityB you could go for:
[$objectA/entityA_entityB != empty and module.entityA_entityB/module.entityA]
First retrieve all the referenced objects of the object you want to compare in the MF.
So let's say you retrieved the referenced objects and stored these in variables $ReferenceSelectorVar1 and $ReferenceSelectorVar2.
Then in xpath, use the retrieved variables like this:
[($ReferenceSelectorVar1 = empty or Object_Reference1 = $ReferenceSelectorVar1)
and
($ReferenceSelectorVar2 = empty or Object_Reference2 = $ReferenceSelectorVar2)]
And so on!