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

Dan Z
  • 696
  • 8
  • 19

1 Answers1

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;
Ivan Stoev
  • 195,425
  • 15
  • 312
  • 343
  • 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 – Dan Z Jun 20 '17 at 13:54
  • 1
    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()` and `FromSql` is an extension method of `IQueryable`. – Ivan Stoev Jun 20 '17 at 14:12
  • 1
    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 :( – Ivan Stoev Jun 20 '17 at 14:28
  • 1
    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. – Dan Z Jun 20 '17 at 16:03