ASP.NET Core快速入门(第6章:ASP.NET Core MVC)--学习笔记
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ASP.NET Core快速入门(第6章:ASP.NET Core MVC)--学习笔记,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3482字,纯文字阅读大概需要5分钟。
内容图文
![ASP.NET Core快速入门(第6章:ASP.NET Core MVC)--学习笔记](/upload/InfoBanner/zyjiaocheng/700/ce3ccdad512f4014b06fdbac67ced4bf.jpg)
课程链接:http://video.jessetalk.cn/course/explore
良心课程,大家一起来学习哈!
任务40:介绍
任务41:Individual authentication 模板
dotnet new mvc --help
Options:
-au|--auth The type of authentication to use
None - No authentication
Individual - Individual authentication
IndividualB2C - Individual authentication with Azure AD B2C
SingleOrg - Organizational authentication for a single tenant
MultiOrg - Organizational authentication for multiple tenants
Windows - Windows authentication
Default: None
-uld|--use-local-db Whether to use LocalDB instead of SQLite. This option only applies if --auth Individual or --auth IndividualB2C is specified.
bool - Optional
Default: false / (*) true
解决VScode终端乱码
chcp 65001
dotnet new mvc -au Individual -uld --name IdentitySample
默认创建localdb,Identity
appsettings.json
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-IdentitySample-40453418-3C8F-43D7-94F8-BD1BD20BDD96;Trusted_Connection=True;MultipleActiveResultSets=true"
}
Startup.cs
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
初始化数据库,根据Data/Migrations文件夹下的数据库文件创建更新数据库
dotnet ef database update
报错:
无法执行,因为找不到指定的命令或文件。
可能的原因包括:
*你拼错了内置的 dotnet 命令。
*你打算执行 .NET Core 程序,但 dotnet-ef 不存在。
*你打算运行全局工具,但在路径上找不到名称前缀为 dotnet 的可执行文件。
在stackoverflow找到解决方法:
在csproj文件的ItemGroup中添加引用
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0-preview2-final" />
dotnet restore
dotnet ef database update
dotnet run
访问https://localhost:5001
点击Register进入注册页面
输入邮箱密码登陆
登陆成功
点击邮箱进入Manage your account
通过SSMS连接localdb
dotnet run
打开PowerShell获取实例管道名称
& 'C:\Program Files\Microsoft SQL Server\130\Tools\Binn\SqlLocalDB.exe' info mssqllocaldb
解决PowerShell中文乱码问题,勾选UTF-8
通过实例管道名称连接localdb
任务42:EF Core Migration
数据库新增
添加列之前
在Models文件夹下新增ApplicationUser.cs
using System;
using Microsoft.AspNetCore.Identity;
namespace IdentitySample.Models
{
public class ApplicationUser : IdentityUser
{
public string NewColumn{get;set;}
}
}
dotnet ef migrations add AddNewColumn
自动生成文件
dotnet ef database update
执行成功后刷新数据库,可以看到数据库中多了一列NewColumn
在ApplicationUser.cs中新增Address
public string Address{get;set;}
dotnet ef migrations add AddAddress
dotnet ef database update
执行成功后刷新数据库,可以看到数据库中多了一列Address
数据库回滚
dotnet ef database update AddNewColumn
执行成功后刷新数据库,可以看到数据库中Address不见了
dotnet ef migrations remove
执行成功后移除AddAddress.cs以及AddAddress.Designer.cs文件
生成sql脚本命令
dotnet ef migrations script
拷贝出来后可在数据库执行
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。
欢迎转载、使用、重新发布,但务必保留文章署名 郑子铭 (包含链接: http://www.cnblogs.com/MingsonZheng/ ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。
如有任何疑问,请与我联系 (MingsonZheng@outlook.com) 。
内容总结
以上是互联网集市为您收集整理的ASP.NET Core快速入门(第6章:ASP.NET Core MVC)--学习笔记全部内容,希望文章能够帮你解决ASP.NET Core快速入门(第6章:ASP.NET Core MVC)--学习笔记所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。