这个访问层的代码实际上是园子里某个前辈的,本人只是觉得好使,记录了下来. 本访问层需要通过Nuget安装EntityFramework Core,不过个人认为EF 6同样可以使用. 搭配数据库,最好是Sql Server(微软支持,你懂的) 下面贴代码 先是IRepository.cs public interface IRepository:IDisposable { //获取一个表的IQuerable接口查询 IQueryable<T> All<T>() where T : c
在应用中使用 SQLite 数据库来存储数据是相当常见的.在 UWP 平台中要使用 SQLite,一般会使用 SQLite for Universal Windows Platform 和 SQLite PCL 之类的库,前者是 SQLite 引擎库,而后者则提供了用于操作数据库的 API ,不过自从 Windows Fall Creators Update 之后,我们有了新的选择. 由于 UWP 在其 Windows Fall Creators Update SDK 中增加对 .NET Sta
新建.net core webapi项目 在NuGet包管理器中搜索 MySql.Data.EntityFrameworkCore并安装,安装的8.0.14版本,只安装这一个就够了 安装后创建DataContext.cs using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; names
一.新建一个Asp.Net Core WebMVC程序 添加nuget包 Mysql.Data 二.新建一个UserContext类 下面代码中的UserInfo是我自己建的一个实体,里面有俩字段:host和name.数据类型都是string MysqlConnection 和MysqlCommand在MySql.Data.MySqlClient命名空间下; public class UserContext { public string ConnectionString { get; set
直接创建WEB项目即可: public class Startup { //startup.cs是站点启动时具体做了哪些事情,主要是开启了一个mvc服务. public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use