I've got a 2.0 server control that uses a dynamic query roughly in the form:
string sql = "Select " + columnvariable + " FROM " + tablenamevariable
So, obviously, you could give it any valid column name from any valid table in the DB and it would return the values in the column into a DataReader (in this case).
I'm trying to cut down on the amount of explicit piecemeal SQL in the codebase and would prefer to do this in LINQ. Is there an easy way to do this? Is it even advisable? I suppose that the resulting piecemeal SQL in this case would be so generic as to not really pose a security problem in this instance.
Even so, it seems like some fairly basic functionality so I'm curious. I've got as far as including System.Linq.Dynamic in my project but this seems to stop shy of allowing a programmer to dynamically select which table they want a dynamic column from.
I don't mean this to be a discussion. I'd like an answer like "Yes, this is possible and trivial, here's how..." or "Yes, but only if you construct this elaborate set of handler classes and basically rewrite parts of LINQ, here's how..."
I would, however, be interested to know whether people think doing this kind of thing in LINQ could best be described as a) a jolly good idea or b) crazy talk.