tags:

views:

85

answers:

3

hi, I have defined the following variable

var result = from report in firoozehDataContext.Reports select report;

now if i want delete One of the columns in the variable, how do i it?

+1  A: 

Use the Dynamic Linq Library

Description related to Linq2Sql by Scott Guthrie

You are interested in the part about dynamic return values.

aanund
A: 

i said i want only show that columns which user want showing in result "NOT FILTERING ROWS"

for example Reports table have 20 columns such as Id, Code, Name Summary and etc, now user want show only Code and Name columns.

however i know can use below code to show only Code and Name columns. but i want selected columns must be dependent on user wants.

var result = from report in firoozehDataContext.Reports
                            select new { report.Code, report.Name };
Sadegh
Don't yell at us. We are here to help you.
Jason
+2  A: 

Unless you have grave concerns about performance, this seems like the kind of thing that should be handled at the UI level and not in your data access code.

I get the impression that you are taking the results of this query and binding to a grid or list with auto-generated columns. However, it is much easier (and safer) to control which columns are visible in a grid than it is to dynamically build a SQL SELECT query. Auto-generated columns are really only appropriate for scaffolding scenarios.

Another good reason why I would recommend against doing what you're doing is that every time your end user decides to hide (or re-show) another column, you're forced to re-run your entire query. This is almost certainly not what you really want.

I would simply select all the columns that could be available and hide the ones that shouldn't be available as part of the UI code.

Aaronaught