These two options can help achieve your goal:
- Using a raw SQL in Entity Framework
- Calling a stored procedure with parameters
Let's see some code:
// your input from a secure source
int input = 1;
// To add where and more lines you can use concatenation or string builder
string sql = $"UPDATE StudentTable SET isUpdate = {input},
updateDate = GETDATE()";
await db.Database.ExecuteSqlRawAsync(sql);
Note: you could use parameters instead of string interpolation for security reasons.
Here's an example with stored procedure and parameters.
using Microsoft.EntityFrameworkCore;
using Microsoft.Data.SqlClient;
//...
int input = 1;
long id = 10;
db.Database.ExecuteSqlRaw("exec [schema].[myCustomSP] @isUpdate, @id",
new SqlParameter("isUpdate", input),
new SqlParameter("id", id));