5

In an ASP.Net Core 1.1 web application, in VS 2017, I need to reference the package:
Microsoft.EntityFrameworkCore.Relational
(this is in order to call stored procedures with result sets as described here: How to run stored procedures in Entity Framework Core?)

When installing the package from PM console, with:

Install-Package Microsoft.EntityFrameworkCore.Relational

I get "Successfully installed 'Microsoft.EntityFrameworkCore.Relational 1.1.2'"

But when I add the line:

using Microsoft.EntityFrameworkCore.Relational;

at the top of the file, the word "Relational" has a red squiggle under with the error:

The type or namespace name 'Relational' does not exist in the namespace 'Microsoft.EntityFrameworkCore' (are you missing an assembly reference?)

I isolated the problem to creating a new project of type "ASP.Net Core Web Application (.Net Framework)", selecting the template for an empty ASP.Net Core 1.1 project, then installing the above package. I still get the same error.
TIA

1 Answer 1

4

Microsoft.EntityFrameworkCore.Relational is assembly. There is no such namespace in EF Core.

The FromSql method is defined in the Microsoft.EntityFrameworkCore namespace, RelationalQueryableExtensions class, so all you need to get access to it is the typical

using Microsoft.EntityFrameworkCore;
Sign up to request clarification or add additional context in comments.

4 Comments

According to the StackOverflow post I linked to, in order to retrieve a typed result set from a stored procedure, I need to use: dbContext.Set() which is in the Microsoft.EntityFrameworkCore.Relational assembly. I did install that assembly as described in my question
That's correct. You need to install the assembly. By doing that it will bring up some additional methods in the aforementioned namespace. Btw, the answer from the link is not quite correct - there is not Set() method, the method is Set<T>() and FromSql is an extension method of IQueryable<T>.
I would suggest you reading the comments under the accepted answer you are referring to. Accepted and upvoted doesn't always mean working. Especially in EF Core where the things change with almost every build :(
Thanks Ivan, I think I've got it now. At the time of the post I got my info from, the Microsoft.EntityFrameworkCore.Relational assembly contained a namespace of the same name, under which was the method FromSql. In the latest version it only adds new classes to the namespace Microsoft.EntityFrameworkCore, and that's where FromSql is now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.