0

I have a very simple scenario:

I have a table having structure:

TableTest:
   - col1
   - col2
   - col3
   - col4

now I have a UI, where user gets to choose out of these columns (columnNames in ListBox or checkboxList for Column Names) and a button.

Now, if user selects first two columns, then, result set should contain rows with only these two Columns. If user selects first three columns, then result set should contains rows with only these three columns.

i.e. I want something similar to below scenario

        MetaTable userMeta = db.Mapping.GetTable(typeof(ThreatMaster));
        var columnNames = userMeta.RowType.PersistentDataMembers;


        IList<string> selectedColumns = columnNames.Where(c=>!c.IsAssociation)
                                       .Select(c=>c.Name).ToList(); 

        objDataContext.TableTests.Select(selectedColumns);

also. I have done objDataContext.TableTests, what If i want to provide columns from different table??

:D:D..am not that efficient in Linq.

please see if my question makes any sense or is valid or i just missed something, some basics and went in the wrong direction

How can I do so? I went through this and this question overhere...

Community
  • 1
  • 1
Manish Mishra
  • 12,163
  • 5
  • 35
  • 59

1 Answers1

0
IList<string> selectedColumns = columnNames.Where(c=>!c.IsAssociation)
                                           .Select(c=>c.Name).ToList();

However, I see that you want to use this result with another select. I recommend you to use dynamic LINQ, here an introduction by Scott

Adrian Iftode
  • 15,465
  • 4
  • 48
  • 73
  • okies @Adrian..i updated my question with your answer, but as u can see, that is not my problem and remotely my answer :D..please help me out – Manish Mishra Jul 20 '12 at 12:05