惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
小众软件
小众软件
Apple Machine Learning Research
Apple Machine Learning Research
Webroot Blog
Webroot Blog
T
The Blog of Author Tim Ferriss
S
Schneier on Security
罗磊的独立博客
P
Privacy & Cybersecurity Law Blog
阮一峰的网络日志
阮一峰的网络日志
F
Fortinet All Blogs
P
Palo Alto Networks Blog
月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog
量子位
NISL@THU
NISL@THU
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
Stack Overflow Blog
Stack Overflow Blog
Recorded Future
Recorded Future
K
Kaspersky official blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
Lohrmann on Cybersecurity
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
L
LINUX DO - 热门话题
Help Net Security
Help Net Security
B
Blog RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Cloudflare Blog
H
Heimdal Security Blog
Last Week in AI
Last Week in AI
美团技术团队
云风的 BLOG
云风的 BLOG
C
Check Point Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
V
Visual Studio Blog
G
GRAHAM CLULEY
AI
AI
Security Latest
Security Latest
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
Cyberwarzone
Cyberwarzone
Microsoft Security Blog
Microsoft Security Blog
P
Proofpoint News Feed

博客园 - 上官帅帅

vue3 - 01 路由的配置和使用 vue 环境配置 vue html DOM树对象 idea maven pom配置文件 .net core dapper (5) .net core dapper (4) .net core dapper (3) .net core dapper (1) c# 异步 async await jq_js window 使用vagrant搭建开发开发环境 判断元素的属性是否存在 js 查找树节点 数组去重 redis 基础知识 jQuey知识点三 解析json数据 mysql 基础操作一 ruby 基础知识三 读写文件 Active Record 数据迁移
.net core dapper (2)
上官帅帅 · 2019-11-26 · via 博客园 - 上官帅帅

  1. 简单的插入数据,然后查询整个表

 1  public static void Main(string[] args)
 2         {
 3             var connectionString = "Server=.;Database=Demo;User Id=sa;Password = keno;";
 4 
 5             //02 insert 
 6             var customerModel = new Customer { CustomerName = "张三", Address = "北京", City = "北京", Country = "中国", PostalCode = "121212" };
 7             using (var connection = new SqlConnection(connectionString))
 8             {
 9                 string sql = "insert into [dbo].[Customer]([CustomerName],[Address],[City],[PostalCode],[Country]) values(@CustomerName,@Address,@City,@PostalCode,@Country)";
10                 var addRow = connection.Execute(sql, customerModel);
11                 Console.WriteLine(addRow);
12 
13                 var customers = connection.Query<Customer>("select * from [dbo].[Customer]").ToList();
14 
15                 foreach (var customer in customers)
16                 {
17                     Console.WriteLine("id: " + customer.CustomerID + " CustomerName:  " + customer.CustomerName + " Address: " + customer.Address + " City: " + customer.City + " PostalCode: " + customer.PostalCode);
18                 }
19             }
20 
21             Console.ReadKey();
22         }

显示结果

2.如果将强类型去掉,他的结果会变成一个动态类型

1 var customers = connection.Query("select * from [dbo].[Customer]").ToList();

3.删除

 1  //03 delete
 2             using (var connection = new SqlConnection(connectionString))
 3             {
 4                 var count = connection.Execute("delete from customer where customerid=@customerId", new { @customerId = 1 });
 5                 if (count > 0)
 6                 {
 7                     Console.WriteLine("Delete Success" + count);
 8                 }
 9                 else
10                 {
11                     Console.WriteLine("Delete Failed" + count);
12                 }
13             }

insert  update delete 使用同一个方法 excuate 返回数据的执行结果

好了今天的内容就写到这儿了,我们都知道在一个复杂的项目中不仅仅是单条数据的 CRUD ,那么我接着下来研究将会是数据的批量执行及数据的复杂查询

see you tomorrow!