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 ...
随机推荐
- 使用docker创建mongodb
1.创建 MongoDB 数据卷 docker volume create mongo_data_yapi 2.启动 MongoDB docker run -d --name mongo-yapi - ...
- frame标签和frameset
框架: 属性 值 描述 frameborder 0 1 规定是否显示框架周围的边框. longdesc URL 规定一个包含有关框架内容的长描述的页面. marginheight pixels 定义框 ...
- spring-data-redis 关于订阅客户端不断创建新线程的问题
项目中使用了spring-data-redis 实现消息订阅功能,原来的配置是这样子: <redis:listener-container connection-factory="je ...
- AXIOS 的请求
AXIOS 本质上等同于json 传值 1.引用 //引入axios import Axios from 'axios' //将axios挂载到 Vue原型上 Vue.prototype.$https ...
- img border
- 移动端touch与click区别--移动端开发整理笔记(五)
移动端用touch还是click? 在移动端开发中,click事件有300ms的延时,由来源于iphone处理双击缩放功能种下的坑.因为用手指在屏幕上快速点击两次,iOS 自带的 Safari 浏览器 ...
- The happy secret to better work,https://www.ted.com/talks/shawn_achor_the_happy_secret_to_better_work/transcript#t-100352
When I was seven years old and my sister was just five years old, we were playing on top of a bunk b ...
- 网页网站基础入门篇: 使用Adobe Dreamweaver CS6 制作网页/网站
咱开发网页或者网站呢,最好使用个软件,我使用的是Adobe Dreamweaver CS6 (自行下载安装) 打开软件 现在呢咱使用 html5 <!doctype html> <h ...
- ESA2GJK1DH1K基础篇: 阿里云物联网平台: 云平台显示单片机采集的温湿度数据,控制设备继电器(基于GPRS模块,AT指令TCP_MQTT通信)
实现的功能 上一节是使用的Wi-Fi模块连接的阿里云平台,这节呢咱用GPRS连接. 阿里云的设备配置还是按照上一节的,有个温度,有个湿度. 测试 一,打开单片机程序 二,根据自己的修改,然后下载进去单 ...
- 洛谷 P1508
P1508 所属知识点:DP 主要题意: 就是求一个矩阵从下边走到上边,可以走自己前方或左前方或右前方. 问走到上边一共经过的路径和. 类型题:P1216 解题思路: 参考上边的类型题(因为比较简单) ...