Can someone show me how to specify which columns I would like to return at runtime from a LINQ To SQL statement?
I allow the user to select items in the checkboxlist that represent the columns that they would like to display in the gridview, tied to the results of the L2S query.
I can dynamically generate a WHERE clause, but I cannot do the same with the SELECT part. Here is an example:
var query = from log in context.Logs select log;
query = query.Where(Log => Log.Timestamp > CustomReport.ReportDateStart);
query = query.Where(Log => Log.Timestamp < CustomReport.ReportDateEnd);
query = query.Where(Log => Log.ProcessName == CustomReport.ProcessName);
foreach (Pair filter in CustomReport.ExtColsToFilter)
{
sExtFilters = "<key>" + filter.First + "</key><value>" + filter.Second + "</value>";
query = query.Where(Log => Log.FormattedMessage.Contains(sExtFilters));
}
source
share