1
votes

I am trying to add entity framework to a .Net Standard 2.0 Class Library.

I have tried creating the classes from the DB. I ran the following Command in the nuget package manager console.

Scaffold-DbContext "Server=localhost;Database=FlexDB;uid=root;pwd=ffff;Trusted_Connection=True;" MySql.Data.EntityFrameworkCore -OutputDir EFModels/DB

It unfortunately produces the following error.

Startup project 'FlexData' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the Entity Framework Core Package Manager Console Tools with this project, add an executable project targeting .NET Framework or .NET Core that references this project, and set it as the startup project; or, update this project to cross-target .NET Framework or .NET Core.

UPDATE-------------

I have followed the instruction from ChrFin but I now get the following error

Could not load type 'Microsoft.EntityFrameworkCore.Infrastructure.DesignTimeProviderServicesAttribute' from assembly 'Microsoft.EntityFrameworkCore, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Blimey it was easier with an EDMX file and template!!!!!

1

1 Answers

1
votes

To run such commands you need a library targeting a runtime (Full or core framework).
Just create an additional project, e.g. a console project targeting .NET 4.5 or newer, and a reference to your .NET standard library.
After setting the new project as the startup project you can then run the command against your original project and get the DB scaffolded in there.