You could use the FromSql extension method to begin a LINQ query based on a raw SQL query.
var blogs = context.Blogs
.FromSql("SELECT * FROM Blogs")
.Where(b => b.Id ==1)
.FirstOrDefault();
Or you could also parameterize user input to prevent the possibility of a SQL injection attack being successful.
var blogs= context.blogs.FromSql("SELECT * From Blogs Where Id = {0}", id).FirstOrDefault();
The SQL command can be any valid SQL statement that returns all the required fields of data. It is possible to call stored procedures via the FromSql method.The DbContext exposes a Database property which includes a method called ExecuteSqlCommand. This method returns an integer specifying the number of rows affected by the SQL statement passed to it. Valid operations are INSERT, UPDATE and DELETE. The method is not used for returning entities.
For more details , you could refer to the following links:
https://learn.microsoft.com/en-us/ef/core/querying/raw-sql
https://www.learnentityframeworkcore.com/raw-sql