C# Dynamic Query Without A Database Model
- by hitopp
I have been searching the web for a solution to dynamic queries.
I have found many different solutions (e.g. Linq to Sql, Dynamic Linq Expressions, Dynamic Query), but all of these solutions involve some sort of previous knowledge of the database (like a model in code). Maybe what I am asking is way off the deep end, but is there any possible way to dynamically query a database without a model?
For example, a database has a Customers table with the following columns:
CustomerID
Name
FavoriteColor
I want to create a query as SELECT Name FROM Customers WHERE @0 = @1, where the two placeholders are populated dynamically. The resulting data does not tie to a model class and I would prefer to use some sort of framework to build the queries, not simple string concatenation.
The System.Linq.Dynamic namespace came really close to fulfilling this request, but it uses a database model.
I realize this is crazy, but I was just curious.