I am trying to call view or store procedure using asp.net core 2.1 on mac os webapi.
using System;
using System.Linq;
using Auth.Database;
using Microsoft.EntityFrameworkCore;
public virtual IQueryable<T> ExecuteStoreProcView(string viewProcName)
{
IQueryable<T> queryResult = _entities.Set<T>().FromSql(viewProcName).AsQueryable();
return queryResult;
}
Getting the below error
Error CS1061: 'DbSet' does not contain a definition for 'FromSql' and no extension method 'FromSql' accepting a first argument of type 'DbSet' could be found (are you missing a using directive or an assembly reference?) (CS1061)
I am developing webapi using entity framework on mac os.
Research some of the queries in below link :- Raw SQL Query without DbSet - Entity Framework Core
Raw SQL Query without DbSet - Entity Framework Core
https://forums.asp.net/t/1886501.aspx?System+Data+Entity+DbSet+Entities+User+does+not+contain+a+definition+for+FirstOrDefault+
https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.relationalqueryableextensions.fromsql?view=efcore-2.1
But not able to find the error solution. Can anyone please let me know what I, am missing.
Entity Framework Core provides the DbSet. FromSql() method to execute raw SQL queries for the underlying database and get the results as entity objects.
FromSqlRaw allows you to use named parameters in the SQL query string, which is useful when a stored procedure has optional parameters: C# Copy.
install Microsoft.EntityFrameworkCore.Relational
nuget package and then add the using statement to the class
using Microsoft.EntityFrameworkCore;
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With