Is it possible to perform a global reversed-find on NHibernate-managed objects?
Specifically, I have a persistent class called "Io". There are a huge number of fields across multiple tables which can potentially contain an object of that type. Is there a way (given a specific instance of an Io object), to retrieve a list of objects (of any type) that actually do reference that specific object? (Bonus points if it can identify which specific fields actually contain the reference, but that's not critical.)
Since the NHibernate mappings define all the links (and the underlying database has corresponding foreign key links), there ought to be some way to do it.
Imagine this sort of structure:
class Io
{
public int Id { get; set; }
// other fields specific to the Io type
}
class ThingOne
{
public int Id { get; set; }
public Io SensorInput { get; set; }
public Io SolenoidOutput { get; set; }
// other stuff
}
class ThingTwo
{
public int Id { get; set; }
public Io SensorInput1 { get; set; }
public Io SensorInput2 { get; set; }
public SubThing Doohickey { get; set; }
// ...
}
class SubThing
{
public int Id { get; set; }
public Io ControlOutput1 { get; set; }
// ...
}
Given a specific instance of Io, I want to discover that it's referenced by the ThingTwo with id 12. Or that it's referenced by that and also by the ThingOne with id 16. If possible, also that the first reference is via SensorInput2, for example.