16

I just built up a bunch of POCO classes and a DbContext class utilizing EntityFramework Core and the Scaffold-DbContext NuGet Package Manager Console command.

It generated a bunch of code and most of it is fine, except there are several calls to HasColumnType and HasName methods that are not found by the compiler. Unfortunately, VS2017 isn't helping me locate them either. I installed EntityFramework Core via the NuGet Package Manager and I figured all dependencies would've been correctly installed, but this does not appear to be the case. I've tried googling the namespace for HasColumnType but have been unable to find it.

Could someone please tell me what namespace or NuGet package I'm missing?

KSwift87
  • 1,843
  • 5
  • 23
  • 40

4 Answers4

46

These extensions are in the Microsoft.EntityFrameworkCore.Relational package as they are useful for modeling relational databases.

https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Relational/

Chris Hutchinson
  • 9,082
  • 3
  • 27
  • 33
  • Thank you sir. Tangentially-related question for you: if this is required for generating EntityFrameworkCore DB code via Scaffold-DbContext, do you know why it's not marked as a dependency of the Microsoft.EntityFrameworkCore package itself, thus being downloaded via NuGet in conjunction with Microsoft.EntityFrameworkCore? – KSwift87 Nov 13 '17 at 16:21
  • The package you should install to run Scaffold-DbContext is the EFCore.Design & the provider package. Both will pull in EFCore package and EFCore.Relational package – Smit Nov 14 '17 at 00:22
  • that's the package I was missing for the `HasFilter()` method https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.relationalindexbuilderextensions.hasfilter?view=efcore-6.0 – devio Feb 17 '22 at 10:01
6

in package manager console hit this command

install-package Microsoft.EntityFrameworkCore.SqlServer

This will automatically install

Microsoft.EntityFrameworkCore.Relational
Microsoft.Data.SqlClient
Goti
  • 59
  • 1
  • 3
4

I also had the same question. As per this Microsoft docs link https://learn.microsoft.com/en-us/ef/core/providers/ you would need to add a specific database provider nuget package, such as Microsoft.EntityFrameworkCore.SqlServer.

EF Core providers for relational databases are build on the common Microsoft.EntityFrameworkCore.Relational library, which provides APIs for configuring table and column mappings, foreign key constraints, etc. Providers are usually distributed as NuGet packages.

So no need to add both packages, adding the more specific one Microsoft.EntityFrameworkCore.SqlServer worked for me.

Deepak Mishra
  • 2,984
  • 1
  • 26
  • 32
0

Met this problem today on .NET Framework 4.7, EF Core version is 3.1.32. the packages and dotnet-ef tool were all installed at correct version (checked thrice) and still compiler doesn't know some symbols like HasColumnType(), HasName() etc. I looked into the packages I have in Rider, turns out the Relational package was there too, except this specific Extension somehow went missing. Kinda weird, since I installed all the packages through Rider's Nuget UI.

I removed all EF Core packages from project and reinstall over again, then did a rebuild. Works now.

Can't remember if I tried rebuilding before reinstalling, but worth a try. Took me an hour or so, so leaving this in case someone runs into it too.

Xiang Wei Huang
  • 336
  • 1
  • 9