Suppose I have 5 table schemas in memory as DataTables and one other DataTable that is a schema of the referential constraints between the other 5 tables.
The 5 schema tables are related such that Table A contains a primary key column related to a foreign key in B. B also contains a primary key column related to a foreign key column in C, and C to D, but suppose A,B,C, and D are not directly or indirectly related to E.
What sort of function would take in two datatables and return a boolean value indicating whether those tables were related or ‘linked’.
What I’m Trying To Accomplish
Suppose I present a user with all of the columns in the 5 tables in a drag and drop style interface. I want the user to be able to build a query a graphically, but I will need to enable/disable certain columns based on whether or not they can even be returned in the same select statement.
You say you have a sixth table containing the constraints between the other tables.
Assuming you can use this info effectively, and are only trying to map direct relationships, you could probably do something like this:
I know this is very high-level and abstract, but I hope it makes sense..
This might take some time to run, depending on the number of tables and complexity of their relationships, but I can’t see any better alternative.
You might store the info about “forbidden” relationships in for instance a Dictionary with a key and a list for each table; something like this (for one-way relationships, to avoid double-registering the info):