Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Core execute sql

Am testing out Entity Framework Core, it's been well so far until i hit an error. I am not able to execute sql from a DbSet with FromSql. Error is dbset does not contain a definition for 'FromSql' The code is

_context.Account.FromSql("Select * from dbo.Account");

What am i doing wrong?

like image 502
Tonto Avatar asked Aug 12 '16 03:08

Tonto


People also ask

Can we use SQL query in Entity Framework?

Entity Framework Core allows you to drop down to SQL queries when working with a relational database.


2 Answers

It happened that I needed one more nuget package to get FromSql as well as Include to work. I added this to my dependencies in the project.json file and after the restore, Voila.

"Microsoft.EntityFrameworkCore.Relational": "1.0.0"

Works now

like image 191
Tonto Avatar answered Sep 21 '22 09:09

Tonto


Please add namespace

using Microsoft.EntityFrameworkCore;
like image 41
ravichandra vydhya Avatar answered Sep 21 '22 09:09

ravichandra vydhya