8

I am building asp.net core web application using full .NET framework 4.6.1 template like this-

1

My project.json shows-

  "frameworks": {
    "net461": { }
  },

I wanted to use EF6 (not EF core), hence install entity framework using NuGet package manager using this command-

Install-Package Entityframework

Project.json added this entry-

"EntityFramework": "6.1.3",

When I am trying to create a DBcontext and model using below Command:

Scaffold-DbContext "Server=XXXXX;Database=XXXXXXX;User Id=XXXXXXX;password=XXXXXXX" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -t TABLENAME

It throws below error:

Scaffold-DbContext : The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or operable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

As I understand (since I have Powershell v3.0 and .NET core 1.0.1), rest of the EF tools and dependencies are missing in my project.json. So which are tools and dependencies I need to add in my project.json to use EF6 (not EF core)?

Some of the options I can see are like below. But not sure which one is right for EF6

"EntityFramework.MicrosoftSqlServer":

enter image description here

"EntityFramework.SqlServer":

enter image description here

"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final"

enter image description here

5
  • You may need to upgrade to powershell 5. See this github issue comment about the same error. Commented Sep 28, 2016 at 18:41
  • I don't have any problem with Scaffold-DbContext. I am confuse here how to use EF6 (not EF core) in ASP.NET core web application(.NET framework 4.6.1)? Commented Sep 29, 2016 at 16:44
  • 2
    you have already read this nice official getting started article docs.asp.net/en/latest/data/entity-framework-6.html ,and noticed "For example, Scaffold-DbContext is only available in Entity Framework Core" do you Commented Sep 30, 2016 at 0:19
  • 1
    Thanks @ergen for clarification that Scaffold-DbContext is only available in Entity Framework Core. I was on wrong track. But my main question still remains open - how to create DBcontext and model with EF6 in ASP.NET core web application(.NET framework 4.6.1)? Commented Sep 30, 2016 at 13:22
  • 1
    @GretelHendricks were you ever able to figure this out? I'm in the same boat but not finding any answers Commented Aug 14, 2018 at 19:03

1 Answer 1

-1

I didn't get what you mean by using core in .net but if you are targeting you project to old .net you need to install compatible version.

For .net 4.8 following package version will work:

Install-Package Microsoft.EntityFrameworkCore.Tools -Version 3.1.25
Sign up to request clarification or add additional context in comments.

2 Comments

Not sure if Microsoft.EntityFrameworkCore.SqlServer is also needed. If yes use, Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.25 Also your provider in scaffold should be System.Data.SqlClient
You can use Entity Framework 6.0 with .net Framework and ASP.NET core, the 3 are compatible. But scaffold-DbContext is not available in EF 6

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.