Why Entity Framework core does not support raw sql query?

entity-framework entity-framework-core

Question

I was using entity framework 6 in my asp.net application and using raw queries like following:

string studentName = ctx.Database.SqlQuery<string>(
         "Select studentname from Student where studentid=1").FirstOrDefault();

Now I am moving my application to asp.net core, but I could not found raw sql query without using DbSet type.

var students = context.Students
                  .FromSql("Select * from Students where Name = 'Bill'")
                  .ToList();

But this does not solve my solutions.

Is there any extension that developed to run sql queries?

1
0
12/3/2019 5:52:48 PM

Popular Answer

You can use the extension method here to create an ad-hoc DbContext for your type: https://github.com/aspnet/EntityFrameworkCore/issues/1862#issuecomment-451671168

0
11/6/2019 5:56:47 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow