I've got a view in SQL Server, and would like to join this view with other tables, through my C# application. To accomplish this, I would need to find out which columns the respective view's fields correspond with, in the underlying table. For example, I could have a view like so:
CREATE VIEW [View A]
AS
SELECT Children.Child_ID, Social_Workers.Social_ID
FROM Children
INNER JOIN Social_Workers
ON Children.Social_ID = Social_Workers.Social_ID
I may want to join a table to the above view. To accomplish this, my C# application must somehow know which are the required foreign key and primary key fields within the relationship, thus generating SQL code like so:
SELECT [View A].Child_ID,
Sponsors.User_ID
FROM [View A]
INNER JOIN Sponsors
ON [View A].Child_ID = Sponsors.Child_ID
I have found a way to retrieve the underlying tables within the view, however I am unsure of how to approach the rest of the problem.