简体   繁体   中英

How can I run Entity Framework commands outside Package Manager Console?

I'm familiar with using Entity Framework commands in Package Manager Console within Visual Studio eg

Scaffold-DbContext "Server=Blah;Database=Blah;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer

I'd like to do the same in an external PowerShell script as part of an automation routine. How would I go about importing Entity Framework tools for use outside of Visual Studio?

I suggest you check out this resource as an introduction into using EF Core with existing databases:

http://www.learnentityframeworkcore.com/walkthroughs/existing-database

You can find an example in the middle for using the command line:

 dotnet ef dbcontext scaffold "Server=.\;Database=AdventureWorksLT2012;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Model

Regarding the -o option:

The -o option (or alternatively --output-dir) specifies the directory where the class files will be generated. If it is omitted, the class files will be generated in the project directory (where the .csproj file is located).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM