var files = from f in context.ExpenseImportFiles where f.FileName.Contains(trimmed)…
- User
var files = from f in _context.ExpenseImportFiles where f.FileName.Contains(trimmed) select f.ExpenseImportId;
var imports = from i in _context.SearchExpenseImports where i.CreatedDate >= searchCriteria.FromDate.Date && i.CreatedDate < searchCriteria.ToDate.Date.AddDays(1) && files.Contains(i.ExpenseImportId) select i;
var result = await imports.OrderByDescending(e => e.CreatedDate).ToListAsync();
to do the same as...
SELECT * FROM SearchExpenseImports WHERE CreatedDate >= '2023-03-29' AND CreatedDate < '2023-04-12' AND ExpenseImportGUID IN ( SELECT ExpenseImportGUID FROM ExpenseImportFiles WHERE FileName LIKE 'cash' )
I still don't know how to combine the two queries into a single EF Core query. Maybe you just can't. The style above doesn't seem intuitive. The final query is close to the SQL. Don't use Contains(trimmed, StringComparison.OrdinalIgnoreCase) or you will get some cryptic error to chase down. You just have to know that Contains(trimmed) will turn into a LIKE statement that is already case insensitive based on your database collation. I'm still on the fence about EF when it comes to search queries. You aren't going to use any of the results with change tracking and it just takes so much more effort.
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.