Adam Reed
Adam Reed

Reputation: 229

Selecting Data from User Input with Entity Framework

I have a form containing some CheckedListBoxes as seen here:

I am able to drill down my data from the first two columns via:

var take = await cmax.dbases.Where(w => statuses.Any(a => w.statusname == a) 
                                        && portfolios.Any(a => w.portfolio == a)).Take(Math.Min((int) takeAmount, count - taken)).ToListAsync();

I would like to then be able to Select() specific data based on my selection in the 2nd two CheckedListBoxes, however, the only method I know to Select Data with EntityFramework is:

Select(s => new { s.ColumnNameHere, s.OtherColumnNameHere });

How may I select the specific properties(columns) based on the user input?

Upvotes: 3

Views: 686

Answers (1)

balbelias
balbelias

Reputation: 428

You may want to use DynamicLinq

With it it's possible to write select statements like that (example from site above):

var query = db.Customers.Select("new (CompanyName as Name, Phone)");

So you need to create a string a list of fields and concatenated them or something else.

Upvotes: 2

Related Questions