Selecting Data from User Input with Entity Framework
I have a form that contains some CheckedListBoxes as shown here:
I can expand my data from the first two columns with:
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 then like to be able Select()
to select specific data based on my selection in the 2nd two CheckedListBoxes, however the only way I know to select data with EntityFramework is:
Select(s => new { s.ColumnNameHere, s.OtherColumnNameHere });
How can I select specific properties (columns) based on user input?
+3
source to share
1 answer
You can use DynamicLinq
With its help, you can write statements like this (example from the site above):
var query = db.Customers.Select("new (CompanyName as Name, Phone)");
So, you need to create a string of the list of fields and concatenate them or whatever.
+2
source to share