I am pretty certain my lack of understanding is preventing me form getting it to work.
I currently have a form that will post filtering parameters back to the controller, then it will build up the query. The current queries I build does not seam to actually do anything. At least not when it is separated like this.
From what I have read, something like this should work, but from what I have tested, it does not.
[HttpPost]
public async Task<IActionResult> FilterPost()
{
var query = _context.Products;
query = query.OrderBy(m => m.Unit.Name)
.Include(m => m.Unit)
.Include(m => m.Attribute);
foreach (var request in Request.Form)
{
var AttributeValue = request.Value;
var AttributeName = request.Key;
query = query.Where(m => m.Attribute.Name == AttributeName)
.Where(m => m.Value >= int.Parse(AttributeValue));
}
return RedirectToAction("Index");
}
This method is probably pretty butchered with all the testing I have done on it.
I have looked into using ExpressionTrees and DynamicLINQ before. They do seam confusingly interestring and perhaps a bit overkill, maybe? I dont know. Maybe I my brain is just too exhausted to see the obvious answer...
I would appreciate any kind of suggestion for a solution or a hint towards an solution.