C# Dynamic Query Without A Database Model

Posted by hitopp on Stack Overflow See other posts from Stack Overflow or by hitopp
Published on 2012-09-21T21:21:01Z Indexed on 2012/09/21 21:38 UTC
Read the original article Hit count: 199

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ