efCore+Mysql+Net Core
1.首先新建一个空的Asp.net core项目

2.新建一个类 gj.cs
public class gj
{
// <summary>
/// 主键
/// </summary>
public int id { get; set; } /// <summary>
/// 标题
/// </summary>
public string method { get; set; }
/// <summary>
/// 内容
/// </summary>
public string text { get; set; } public string type { get; set; }
}
3.添加数据库上下文类。
public class DbGj:DbContext
{
public DbSet<gj> gj { set; get; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseMySQL(@"Server=localhost;database=testapp;uid=root;pwd=woshishui");
}
4.添加控制器
public class GJController : Controller
{ public IActionResult Index()
{
using (var db = new DbGj())
{
var lis = db.Set<gj>().ToList();
return View(lis);
} } }
5.视图
@model IEnumerable<CoreTest_1.Models.gj>
@{
ViewData["Title"] = "Index";
}
<h1>Index</h1>
<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.method)
</th>
<th>
@Html.DisplayNameFor(model => model.text)
</th>
<th>
@Html.DisplayNameFor(model => model.type)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.method)
</td>
@*<td>
@Html.DisplayFor(modelItem => item.text)
</td>*@
<td>
@Html.DisplayFor(modelItem => item.type)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.id">Edit</a> |
<a asp-action="Details" asp-route-id="@item.id">Details</a> |
<a asp-action="Delete" asp-route-id="@item.id">Delete</a>
</td>
</tr>
}
</tbody>
</table>
F5运行程序 (如图)

efCore+Mysql+Net Core的更多相关文章
- EFCore+Mysql仓储层建设(分页、多字段排序、部分字段更新)
前沿 园子里已有挺多博文介绍了EFCore+Mysql/MSSql如何进行使用,但实际开发不会把EF层放在Web层混合起来,需要多个项目配合结构清晰的进行分层工作,本文根据个人实践经验总结将各个项目进 ...
- asp.net core + mysql + ef core + linux
asp.net core + mysql + ef core + linux 以前开发网站是针对windows平台,在iis上部署.由于这次需求的目标服务器是linux系统,就尝试用跨平台的.NET ...
- Spring Boot连接MySQL长时间不连接后报错`com.mysql.cj.core.exceptions.ConnectionIsClosedException: No operations allowed after connection closed.`的解决办法
报错:com.mysql.cj.core.exceptions.ConnectionIsClosedException: No operations allowed after connection ...
- Asp.Net Core Identity+EFCore + Mysql踩坑记录
搭建基础框架准备试试传说中的Identity,本以为很顺利,结果一路踩了N多坑 遂就把过程记录下来.方便自己以后查看,也希望能帮到遇到同样问题的朋友. 1.首先,引入Identity需要的类库,还有M ...
- CodeFirst+MySQL+.Net Core配置详情
EF 基础操作:http://www.cnblogs.com/M-LittleBird/p/5852395.html 一.使用CodeFirst模式 1.在需要添加的项目上右键点击选择添加ADD.NE ...
- Mysql EF Core 快速构建 Web Api
(1)首先创建一个.net core web api web项目; (2)因为我们使用的是ef连接mysql数据库,通过NuGet安装MySql.Data.EntityFrameworkCore,以来 ...
- com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value '��� mysql-installer-community-8.0.15.0
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> &l ...
- EFCore.MySql当模型遇到int[]怎么办
我使用的是Pomole.EntityFrameworkCore.MySql 需要将旧项目中的excels表转成实体,其中有一列是json格式的int[] 当遇到第一张表的时候,我使用了这样的方法来读取 ...
- Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone. You must configure either the
mysql6.0里面改成新的配置方式: hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect #old #driverClassNam ...
随机推荐
- 使用fio命令查看磁盘iops
具体命令: fio -filename=./localhost.2019-05-08.log -direct=1 -iodepth 1 -thread -rw=randrw -ioengine=psy ...
- [PAT] 目录
题号 PAT Basic PAT Advaced PAT Top 1001 害死人不偿命的(3n+1)猜想 1002 写出这个数 1003 我要通过! 1004 成绩排名 ...
- mysql在windows下安装(含客户端工具)
下载 http://dev.mysql.com/downloads/ 安装 在出现选择安装类型的窗口中,有“typical(默认)”.“Complete(完全)”.“Custom(用户自定义)”三个选 ...
- AcWing 38. 二叉树的镜像
习题地址 https://www.acwing.com/solution/acwing/content/2922/ 题目描述输入一个二叉树,将它变换为它的镜像. 样例 输入树: / \ / \ / \ ...
- 《浅谈我眼中的express、koa和koa2》好文留存+笔记
原文 :三英战豪强,思绪走四方.浅谈我眼中的express.koa和koa2 一.回调大坑怎么解决呢? 1.es5可以利用一下第三方库,例如 async 库, 2.或者单纯使用 connect中间件 ...
- scannet数据集
数据集包含xyz和label信息,不包含颜色信息. 一共1513个室内场景数据(每个场景中点云数量都不一样),共21个类别的对象(0-20,总共已知类别应该是20,类别0应该是未知类别,即未标注点云) ...
- Codeforces Round #603 (Div. 2) E - Editor(线段树,括号序列)
- restql 学习二 几种查询模式
restql 提供了比较强大的查询处理. 支持的几种查询模式 基本查询,主要是单一映射资源的查询,(from,with,only,header,cache...) 并行查询,多个资源的同时查询,(对于 ...
- 踩iviewui中Tabs 标签页数据绑定坑
今天小颖要实现点击Tabs 标签页中每个标签,并动态获取当前点击的标签值. 一句话说不清楚,那就看动态图吧 小颖一开始看官网写的代码是: <template> <Tabs :valu ...
- vue+element 表单验证
效果图 <template> <div class="formValidator"> <div v-for="(item,index) in ...