I have this Iqueryable IQueryable<ScreenerData> query = _context.ScreenerData;
which is financial metrics I have made a screener which filters out items. But I want to return some fixed data which doesnt change + the conditions based on my input so for example the fixed data might be something like revenue, pe, ebit but in the filter I have something like marketcap > 1000 and so i want to pass back revenue, pe, ebit, marketcap
query = query
.Where(i => i.security_type == "stock")
.Where(i => i.screener_last_updated != null)
.Where(i => i.screener_last_updated >= tenDaysAgo)
.Where(i => siQIds.Contains(i.id))
.OrderByDescending(sortLambda);
I am currently doing the above and then using reflection to get all the items:
var properties = typeof(ScreenerData).GetProperties();
var selectedData = new List<Dictionary<string, object>>();
foreach (var item in query){
var data = new Dictionary<string, object>();
foreach (var property in properties)
{
if (conditions.Any(c => c.variable == property.Name))
{
data[property.Name] = property.GetValue(item);
}
}
data["id"] = item.id;
data["revenue"] = item.revenue;
data["pe"] = item.pe;
data["ebit"] = item.ebit;
}
This works fine except that its essentially doing select * from table where as i want it to select id, revenue, pe, ebit, marketcap from table.
Would really appreciate some help on this as I have tried some different examples on stack overflow and couldnt get them to work