I realise that this is an old question, but here are some answers anyway.
You have 2 options, depending on what you are trying to do:
Option 1: DbSet FromSql
using Microsoft.EntityFrameworkCore;
...
var sql = "select * from clients";
var clients = _clientDbContext.Clients.FromSql(sql);
Note that this requires you to have a Client entity matching the output of the sql statement and the related DbSet defined on your DbContext implemementation.
Option 2: Raw data access
using (var conn = (SqlConnection)((DbContext)_clientDbContext).Database.GetDbConnection())
{
conn.Open();
using (var reader = new SqlCommand(sql, conn).ExecuteReader())
{
...
}
conn.Close();
}
Now you have access to the raw DbConnection and the ADO.NET world and can use SqlCommand, DataTables etc to run any SQL and manage the data returned yourself.
I would caution you against mixing Entity Framework and direct SQL database updates - but this can be useful for picking up a small piece of data - maybe a config value, or running a stored procedure.
usingdirectives in your file? A simpleusing Microsoft.EntityFrameworkCore;should do the trick to get you theFromSql()call.