I'm looking for a way to take an SQL query, pass it to a method, and retrieve a dictionary back of all of the columns and their associated table. I was able to get a list of tables from a query based on this: List of tables used in an SQL Query
For example, the following query:
SELECT P.FirstName, P.LastName, P.BirthDate, P.DeathDate, VP.FullName
FROM Presidents P
INNER JOIN VicePresidents VP ON P.VicePresidentID = VP.VicePresidentID
Ideally, it would return a dictionary (or keyvaluepair or whatever really) item with the following:
{FirstName, Presidents},
{LastName, Presidents},
{BirthDate, Presidents},
{DeathDate, Presidents},
{Fullname, VicePresidents}
Ideally, this should not touch SQL at all (if possible). The identifiers (P,VP) may not always be there. My method that returns tables does return Presidents and VicePresidents, but I really need the column/table relationship. Any thoughts?
I'm creating an MVC control, that you pass an object from the model and it automatically creates the entire form based on the model. The object from the model matches a sql query used to fill it. I have parameters for lookups and many of the input types. The one thing I can't do automatically though is the table name for the column.
I have this query:
SELECT
AppSettingsTypeID,
AppSettingsTypeName
FROM MasterImport.DBAppSettingsType
WHERE AppSettingsTypeID = 13
That creates an instance of this class
public class DBAppSettingFull
{
[FormField("App Setting Type", InputType.Dropdown, new int[] { 12, 12, 6, 6, 4 })]
public int AppSettingsTypeID { get; set; }
[FormField("App Setting Name", InputType.Textbox, new int[] { 12, 12, 6, 6, 4 })]
public string AppSettingsTypeName { get; set; }
}
With this line of code
model.Record = Interaction.Single<DBAppSettingFull>(sqlGeneric.GetFirstDBAppSetting.Resource());
Which is used in the cshtml with this line of code
@(Html.GenerateForm<Cold.Framework.Classes.DBAppSettingFull>(Model.Record))
and it creates the form on the cshtml page. I'm in the process of writing my ProcessForm method. My last version of this, I had to do manually give each property/column its table relationship. I'd like to do that automatically.