question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with database first scaffolding

See original GitHub issue

I’m having problem with scaffolding DbContext. I’m using latest .NET Core 1.1.0 SDK. I’m following this guide: https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db

But when I run following command in Package Manager Console: Scaffold-DbContext "<connection-string>" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models I get exception.

project.json

  "dependencies": {
    "Microsoft.EntityFrameworkCore": "1.1.0",
    "Microsoft.EntityFrameworkCore.Design": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
    "NETStandard.Library": "1.6.1"
  },

  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": [
        "dnxcore50"
      ]
    }
  }

Exception

System.IO.FileNotFoundException: Could not load file or assembly 
'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
   at Microsoft.EntityFrameworkCore.Scaffolding.RelationalScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqlServerScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GetMetadataModel(ReverseEngineeringConfiguration configuration)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContextAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<ScaffoldContextImpl>d__22.MoveNext()
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source, Int32& length)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Xamarianscommented, May 11, 2017

I were having the same error. Fixed by making it default project (“Set as Startup Project”).

1reaction
LoopsLucommented, Feb 8, 2017

I use this project.json. I think it is enough. I copied some settings from the WebApi project, and it works as well as the WebApi project in my Library project.

{ “dependencies”: { “Microsoft.NETCore.App”: { “version”: “1.0.1”, “type”: “platform” }, “Microsoft.EntityFrameworkCore”: “1.1.0”, “Microsoft.EntityFrameworkCore.SqlServer”: “1.1.0”, “Microsoft.EntityFrameworkCore.SqlServer.Design”: “1.1.0”, “Microsoft.EntityFrameworkCore.Tools”: “1.1.0-preview4-final”, “NETStandard.Library”: “1.6.1” },

“frameworks”: { “netcoreapp1.0”: { “imports”: [ “dotnet5.6”, “portable-net45+win8” ] } } }

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Build failed" on Database First Scaffold-DbContext
This error can cause both when you add a command for Migration (what was my case) or Scaffolding the DB. When you start...
Read more >
Is there an official Database First Approach in EF Core?
I was talking with a tech architect who claimed the Database First Approach was available in EF Core via the scaffold-dbcontext command.
Read more >
7.2.2 Scaffolding an Existing Database in EF Core
Scaffolding a database produces an Entity Framework model from an existing database. The resulting entities are created and mapped to the tables in...
Read more >
Entity Framework Core - Scaffold Existing Database
In this video, we explore generating a Code First Database model from an existing database. Sometimes, doing code first is not an option,...
Read more >
Generating a model from an existing database
The following example illustrates how to use code first to generate a model from a SQL Server database in a new console application...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found