Run a raw sql query/command via EF Core
There are different ways to run a SQL command/query in Entity Framework Core.
1.DbSet.FromSqlRaw
var parentsList = context.Parents
.FromSqlRaw("Select * from dbo.Parents where IsRich = 0 ")
.ToList();
2.*DbSet.SqlQuery
var countOfParents = context.Database.SqlQuery<int>("Select Count(*) from dbo.Parents where IsRich = 0");
3.Database.ExecuteSql
var numberOfAffectedEtntities = context.Database.ExecuteSqlCommand("DELETE FROM dbo.Parents WHERE Id = 1");
4.Database.Database.ExecuteSqlRaw
var numberOfAffectedEtntities = context.Database.ExecuteSqlRaw("DELETE FROM dbo.Parents WHERE Id = 1");