Using LINQ to select columns from table based on metadata values

  • Thread starter Thread starter markeboy
  • Start date Start date
M

markeboy

I want the user to be able to define the columns they wish to retrieve from a
datasource. Is it possible to "pass in" the column names required?

Or put another way, is it possible to select say columns A M and Z from
tableX where "A", "M" and "Z" are in say a string array?
 
The question is whether filtering the data on the data query is your real
goal. If you have just a few items that can be selected on a single row, you
might be better to grab all columns and then filter what you display on the
UI. This leaves your object definition the same no matter what the user
chooses to display. And, it is a better pattern, in many ways, as the
business object is constant and display (which is a UI function) changes.

Without knowing your application, I cannot state if the above pattern is a
better pattern or not. I am also not certain about dynamic altering LINQ
queries, so I will have to defer on that answer until I play some more. You
could go into Reflection.Emit() and dynamically create the assembly to get
the data, but this makes for a rather complex application ... that might not
need to be so complex.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
 
Back
Top