Entity Framework DB First 连接Linux云服务器Docker中的Sql Server
程序包管理器控制台 选择数据库项目
Scaffold-DbContext -Connection "Server=***.***.***.***;Database=test;User ID=sa;Password=********" -Provider "Microsoft.EntityFrameworkCore.SqlServer" -OutputDir "Models"
使用工具的scaffold-dbcontext(数据库上下文脚手架)指令来生成models和context
指令详细介绍:
Scaffold-DbContext [-Connection] <String> [-Provider] <String> [-OutputDir <String>] [-Context <String>]
[-Schemas <String>] [-Tables <String>] [-DataAnnotations] [-Force] [-Project <String>]
[-StartupProject <String>] [-Environment <String>] [<CommonParameters>]
PARAMETERS
-Connection <String> 数据库的连接字符串。
Specifies the connection string of the database.
-Provider <String> 要使用的提供程序(例如 Microsoft.EntityFrameworkCore.SqlServer)
Specifies the provider to use. For example, Microsoft.EntityFrameworkCore.SqlServer.
-OutputDir <String> 要将文件放入的目录 路径是相对于项目目录。
Specifies the directory to use to output the classes. If omitted, the top-level project directory is used.
-Context <String> 若要生成的 dbcontext 名称
Specifies the name of the generated DbContext class.
-Schemas <String> 要生成实体类型的表架构
Specifies the schemas for which to generate classes.
-Tables <String> 要生成实体类型的表
Specifies the tables for which to generate classes.
-DataAnnotations [<SwitchParameter>] 使用属性来配置该模型 (如果可能)如果省略,则使用仅 fluent API
Use DataAnnotation attributes to configure the model where possible. If omitted, the output code will use only the fluent API.
-Force [<SwitchParameter>] 覆盖现有文件
Force scaffolding to overwrite existing files. Otherwise, the code will only proceed if no output files would be overwritten.
-Project <String>
Specifies the project to use. If omitted, the default project is used.
-StartupProject <String>
Specifies the startup project to use. If omitted, the solution's startup project is used.
-Environment <String>
Specifies the environment to use. If omitted, "Development" is used.