I have .NET 5 MVC project (original ASP.NET 3.1 Core MVC), where I use EF Core 5 + React + Redux and MSSql.
I looking for a find way, how to send via REST GET request, data from React form (the form with, select, input, range boxes) into the backend and autogenerate WHERE SQL query from the sand filters, with selected values.
Is there any EF Core feature or I must generate this query for example in FOREACH like:
query = ...
foreach param_filter in
query = query.Where(...)
I have an HTML form with filters and their values are generated from DB, and each website page has another count and types of filters, but each filter has a unique string ID
ADD INFO:
Input request:
{
"name": "Application",
"values": [
{
"name": "Smart Homes & Cities | Industrial | Automotive | Security | Consumer",
"value": "Smart Homes & Cities | Industrial | Automotive | Security | Consumer"
}
],
"type": "select",
"field": "ant_application",
"sort": 4
}
I would like to get REST API request with filters array, and for each field type, generate something like:
foreach (var f in filters)
query.Where(p => p.Field == p.field).AndValueNotIn(f.values);
Where p means products list, where each product has its own field values
Now I use in EF Core DB procedure call like:
.FromSqlInterpolated($"EXEC GetGroupFilters {groupId}").AsEnumerable()
MSSql procedure has the only SQL (join, select, union), and returns formatted rows from DB which I load into Object and use LINQ, I have 2 choices:
- generate raw text from filters with SQL WHERE and send it into the procedure
- generate LINQ .Where() etc in backend side with C#
I think then choice number 1 will be faster and better, but still, find the best solution
Is there any better solution?
question from:
https://stackoverflow.com/questions/65952916/entity-framework-core-in-asp-net-5-web-project-autogenerate-linq-filters-query