加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

基于.NET Core 3.1 网站开发和部署的方法

发布时间:2020-09-18 08:50:35 所属栏目:Asp教程 来源:网络整理
导读:副标题#e# 一、准备开发环境1.主要开发工具的选择 vscode .NET Core command-line interface (CLI) tools Dbeaver 这里选择vscode + .net core cli 是因为不管在Windows还是Linux和Mac上都能使用这一套工具,而且命令行工具也非常强大。 2.vscode安装C#插件

D:dotnet_coreHotelWebMVC>dotnet sln ./HotelWebMVC.sln add DALDAL.csproj 已将项目“DALDAL.csproj”添加到解决方案中。 D:dotnet_coreHotelWebMVC>dotnet sln ./HotelWebMVC.sln add BLLBLL.csproj 已将项目“BLLBLL.csproj”添加到解决方案中。 D:dotnet_coreHotelWebMVC>dotnet sln list 项目 -- HotelWebMVCHotelWebMVC.csproj ModelsModels.csproj DALDAL.csproj BLLBLL.csproj

添加启动项目和类库项目之间的引用

Models -->DAL

D:dotnet_coreHotelWebMVCDAL>dotnet add reference ..ModelsModels.csproj 已将引用“..ModelsModels.csproj”添加到项目。

DAL —> BLL

D:dotnet_coreHotelWebMVCDAL>dotnet add ..bllBLL.csproj reference .DAL.csproj 已将引用“..DALDAL.csproj”添加到项目。

HotelWebMVC --> BLL

D:dotnet_coreHotelWebMVCDAL>dotnet add ..HotelWebMVCHotelWebMVC.csproj reference ..bllBLL.csproj 已将引用“..bllBLL.csproj”添加到项目。

2.生成Model

① 使用EF Core 生成模型

DB First模式

全局安装ef工具

dotnet tool install --global dotnet-ef

测试工具是否安装成功

D:dotnet_coreHotelWebMVC>dotnet ef _/__ ---==http://www.jb51.net/ ___ ___ |. | | __|| __| | ) | _| | _| _/ | //| |___||_| / / Entity Framework Core .NET Command-line Tools 3.1.0 Usage: dotnet ef [options] [command] Options: --version Show version information -h|--help Show help information -v|--verbose Show verbose output. --no-color Don't colorize output. --prefix-output Prefix output with level. Commands: database Commands to manage the database. dbcontext Commands to manage DbContext types. migrations Commands to manage migrations. Use "dotnet ef [command] --help" for more information about a command.

只要看到有这个独角兽就代表安装成功了。

添加需要的NuGet包

dotnet add package Microsoft.EntityFrameworkCore.Design dotnet add package Pomelo.EntityFrameworkCore.MySql

使用EF工具

查看帮助

D:dotnet_coreHotelWebMVCDAL>dotnet ef dbcontext scaffold --help Usage: dotnet ef dbcontext scaffold [arguments] [options] Arguments: <CONNECTION> The connection string to the database. <PROVIDER> The provider to use. (E.g. Microsoft.EntityFrameworkCore.SqlServer) Options: -d|--data-annotations Use attributes to configure the model (where possible). If omitted, only the fluent API is used. -c|--context <NAME> The name of the DbContext. --context-dir <PATH> The directory to put DbContext file in. Paths are relative to the project directory. -f|--force Overwrite existing files. -o|--output-dir <PATH> The directory to put files in. Paths are relative to the project directory. --schema <SCHEMA_NAME>... The schemas of tables to generate entity types for. -t|--table <TABLE_NAME>... The tables to generate entity types for. --use-database-names Use table and column names directly from the database. --json Show JSON output. -p|--project <PROJECT> The project to use. -s|--startup-project <PROJECT> The startup project to use. --framework <FRAMEWORK> The target framework. --configuration <CONFIGURATION> The configuration to use. --runtime <RUNTIME_IDENTIFIER> The runtime to use. --msbuildprojectextensionspath <PATH> The MSBuild project extensions path. Defaults to "obj". --no-build Don't build the project. Only use this when the build is up-to-date. -h|--help Show help information -v|--verbose Show verbose output. --no-color Don't colorize output. --prefix-output Prefix output with level.

连接数据库生成模型数据

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读