开发者

remove column from variable (LINQ)

开发者 https://www.devze.com 2022-12-13 14:42 出处:网络
I have defined the following variable var result = from report in firoozehDataContext.Reports select开发者_Go百科 report;

I have defined the following variable

var result = from report in firoozehDataContext.Reports select开发者_Go百科 report;

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


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.


Use the Dynamic Linq Library

Description related to Linq2Sql by Scott Guthrie

You are interested in the part about dynamic return values.

0

精彩评论

暂无评论...
验证码 换一张
取 消