Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 408
Adam Reed Avatar asked Sep 13 '26 12:09

Adam Reed


1 Answers

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.

like image 64
balbelias Avatar answered Sep 16 '26 06:09

balbelias