Error CS1061: 'DbSet<T>' does not contain a definition for 'FromSql' and no extension method 'FromSql' accepting a first argument of type 'DbSet<T>'

23,228

Solution 1

install Microsoft.EntityFrameworkCore.Relational nuget package and then add the using statement to the class

using Microsoft.EntityFrameworkCore;

Solution 2

This might have changed since Umer answered. It is now in the Microsoft.EntityFrameworkCore namespace. But you will need to reference the package.

So...

dotnet add package Microsoft.EntityFrameworkCore.Relational

And add this line...

using Microsoft.EntityFrameworkCore;

Solution 3

In the latest version, Microsoft renamed this method to:

FromSqlInterpolated()

https://docs.microsoft.com/en-us/ef/core/querying/raw-sql

So you'll have to find/replace all the code using .FromSql to .FromSqlInterpolated. They discuss the motivation in the above document, although I have to say the length of the new method name is unwelcome.

What the other answers say is still necessary - you'll need to have installed the Nuget package Microsoft.EntityFrameworkCore.Relational, and, have added a using statement for Microsoft.EntityFramework.

Solution 4

It solved for me with this using this line:

using Microsoft.EntityFrameworkCore;

Solution 5

Hope this might be useful as it's related to the above issue and is likely that others will have the same problem. I was not able to access .FromSql inside of a service that resided in a seperate service project from the Web.Api (MVC Project) I was able to access the .FromSql from within a controller in the Web.Api project. What confused me was that there is no direct reference in the web.api project for Microsoft.EntityFrameworkCore.Relational The Microsoft.EntityFrameworkCore.SqlServer nuget package is referenced by the EntityFramework project. By adding a reference to the service project the services are now able to use the .FromSql. It's been a long day but I still don't know why the web.api works but the service project needs a direct reference.

Share:
23,228

Related videos on Youtube

San Jaisy
Author by

San Jaisy

Updated on April 05, 2022

Comments