-
Website
http://www.emadibrahim.com -
Original page
http://www.emadibrahim.com/2008/05/12/dynamically-build-linq-queries-using-reflection/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
danatkinson
1 comment · 1 points
-
Korayem
3 comments · 1 points
-
dukon21
1 comment · 1 points
-
Mladen Mihajlovic
1 comment · 1 points
-
Chad Myers
3 comments · 1 points
-
-
Popular Threads
-
Select Random Records Using Nhibernate
1 week ago · 4 comments
-
Select Random Records Using Nhibernate
Also, your dynamicClass string generation could be rewritten as a much simpler one-liner:
string dynamicClass = "new(" + string.Join(",", columnsToExport) + ")";
I'm assuming you validate for a positive number of selected columns somewhere else.
Using reflection and custom attribute also allowed me to specify which columns can be exported and which ones can't. So that alone, would prevent me from using regular sql strings and executing on a command.
On the other hand, you are right, almost everything I did could have been done with a sql string and a command but where is the fun in that :)
Thanks for the string.Join... I am embarrassed to say that I have never used it before and looking at your code snippet - I LOVE IT.
if you do find, please come back and let us know. It will help future
readers.
Thanks.