Make sure you add using Microsoft.Data.Entity; because there is an extension method you could use.

var rawSQL = dbContext.SomeModels.FromSql("your SQL");

Even better, instead using raw SQL (at risk of SQL injections attacks) this FromSql method allows you to use parameterized queries like:

dbContext.SomeModels.FromSql("SELECT * FROM dbo.Blogs WHERE Name = @p0", blogName);


In EF Core you no longer can execute "free" raw sql. You are required to define a POCO class and a DbSet for that class. In your case you will need to define Rank:

var ranks = DbContext.Ranks
   .FromSql("SQL_SCRIPT OR STORED_PROCEDURE @p0,@p1,...etc", parameters)

As it will be surely readonly it will be useful to include the .AsNoTracking() call.


What's New in Entity Framework Core 2.0
• EF Core now targets the new .NET Standard 2.0
• Improved LINQ translation
• Owned entities and Table Splitting
• Global query filters
• DbContext Pooling
• String interpolation in raw SQL methods