I am working on an object relational mapper of sorts, which needs to dynamically create multi-table SQL statements at run time.
The database structure is only known at run time, which rules out using LINQ to SQL in its intended fashion.
However, I would like to tap into the LINQ to SQL query generation capabilities at run time if possible. Maybe this can be done by creating the "LINQ to SQL" data context at run time, and use the SQL query generation capabilities?
Alternatively, is there any other .NET libraries out there that will allow dynamic query creation from a database structure only known at run time?
Example of a generated query:
SELECT
T1.Name,
T2.Category,
T3.MainCategory
FROM products t1
LEFT JOIN categories t2
ON t2.CategoryId = t1.CategoryId
LEFT JOIN MainCategories t3
ON t3.MainCategoryId = t2.MainCategoryId
WHERE t3.Active = 1
ORDER BY t2.Category, t1.Name
My application already handles deciding which tables and fields are required, as well as filters and sorting, and this information is available at run time. I would rather translate this to another SCHEMA of sorts, like a DataContextDataClasses object, rather than building the SQL text manually.
Any advice or direction much appreciated.