一:什么是Dapper
Dapper是一个适用于.NET平台的开源的数据-实体映射框架。
由全球最大的开发者问答社区Stackoverflow.com开发者开发并维护
二:几大特性
轻量:早期的Dapper只有一个类文件;
稳定、高效:接近Ado.net的读写速度;
支持多种数据库:SQL Server、Oracle、MySql、Sqlite
跨平台:支持.NET Core
===============================================================
项目的App.config中配置连接字符串:
<!--Oracle数据库配置-->
<add key="OrclConnect" value="Data Source = localhost/ORCL; User Id = android; Password=android;" />
数据库访问层DbHelper中添加访问连接字符串:
using System.Configuration;
//从配置文件中读取数据库连接字符串
public static string ConnectionString
{
get{ return ConfigurationManager.ConnectionStrings["OrclConnect"].ConnectionString;}
}
using(IDbconnection db = new SqlConnection(DbHelper.ConnectionString))
{
string sql = "select * from person";
IEnumerable<Person> list = db.Query<Person>(sql);
}
数据库随机数据生成器:http://www.mockaroo.com/
教程:http://www.yuanjiaocheng.net/Dapper/dapper.html