You are actually on the right track. Retrieving B is equal to retrieving D if B is a actually a B. Given the fact that Inheritance means All specializations are also their generalisation. Thus a D object is always a B object as well.
With this in mind; if you are able to retrieve the B, you can determine the D by using a inheritance split.