I’m using Microsoft.Data.Sqlite;
to query an SQLite
db.
The structure of mytable
table and the large size means that I need to provide handwritten sql for efficient data retrieval.
var myresult = dbContext.MyTable.FromSqlInterpolated($"select * from mytable where numericValue >= {dynamicNumericValueHere} limit 10;").ToList();
which generates this SQL
select * from mytable where numericValue >= @p0 limit 10;
This works fine, however I’m having to use an inline sql string and this is a simplified version of the SQL. The actual SQL has multiple lines, with multiple parameters.
There may also be different versions of the sql string I need to use.
What can I do to move this sql out of this c# file while ensuring that I use parameterised queries to prevent SQL Injection, so that I can keep the sql lines organised separately in a different file?
Thanks