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

推荐订阅源

L
LangChain Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
Webroot Blog
Webroot Blog
MongoDB | Blog
MongoDB | Blog
AI
AI
WordPress大学
WordPress大学
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
L
LINUX DO - 最新话题
T
Troy Hunt's Blog
J
Java Code Geeks
F
Fortinet All Blogs
The Cloudflare Blog
Cisco Talos Blog
Cisco Talos Blog
S
SegmentFault 最新的问题
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
M
MIT News - Artificial intelligence
The Hacker News
The Hacker News
G
GRAHAM CLULEY
H
Hacker News: Front Page
V
Vulnerabilities – Threatpost
L
Lohrmann on Cybersecurity
P
Privacy International News Feed
N
News and Events Feed by Topic
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cyberwarzone
Cyberwarzone
T
Threatpost
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
S
Securelist
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Project Zero
Project Zero
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Tailwind CSS Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
A
About on SuperTechFans
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - craboYang

JVM: can not create native thread 注解式功能权限控制机制 SqlInXml 动态配置化 ElasticSearch5集群部署指南 Solr5 DataImport 处理1对多关系 C# XMPP客户端与openfire通信(Matrix Xmpp 授权破解教程) 响应式编程 Part.01 (Layout and MVVM) Mono.Ceil 无法保存Silverlight 程序集 基于system.diagnostics Trace的日志输出 Dappers 开发入门 (5) - 缓存 Dappers 开发入门 (4) - 明细编辑 Dappers 开发入门(3)- 列表界面 Dappers 开发入门(2) - Mapping Dappers 开发入门(1) - 接口 Dappers : 基于Dapper.net 扩展的Dao B/S页面 通用权限控制(2) B/S页面 通用数据权限控制 由于ContractFilter在EndpointDispatcher不匹配,因此Action为<BtsActionMapping...的消息无法在接收方处理 - craboYang - 博客园 WinForm DataGridView 绑定后仅显示许多空行和空格
Dappers : 基于Dapper.net 扩展的Dao - Part II
craboYang · 2011-09-30 · via 博客园 - craboYang

用习惯Linq2Sql的盆友肯定对 from... where....select 这种inline式,强类型的 写法大爱不已.

可惜我不是,对于表关联, 这种写法及其最终sql 分析都非常 egg疼, 于是乎Dapper作者博客里就有不少将原Linq2sql 转 sql dapper的心得.

但是,我完全同意: 在一般简单查询,Lambda写起来更顺手,更美观,更强类型. (Lambda解析转SQL语句,请看这里)

所以我的Dappers 里 又加了个接口. 所有这些,都是面向sql, 面向跨oracle / sql server 的.  

1. 如果彻底不写SQL, 数据库的基本信息还是需要的 

[System.Data.Linq.Mapping.Table(Name = "SYS_OFFICE")]
    public class MyOffice
    {
        [System.Data.Linq.Mapping.Column(Name = "OfficeId", IsPrimaryKey = true)]
        public string Id { getset; }
        public string Name { getset; }
        public string OfficeType { getset; }
        ......

 2. Query<T>(whereExpression)

var user = dao.Query<MyUser>(u =>  u.UserCode.StartsWith("chen"));//此时用到上述mapping,否则无需描述mapping

var user1 = dao.Query<MyUser,MyOffice>("select t.* from SYS_USER t inner join SYS_Office t1 on t.OfficeId=t1.Id",
 (u,o) => u.UserCode.StartsWith("chen") && o.Name.Contains("办公室"));

var user2 = dao.Query<IDictionary,MyUser, MyOffice>("select t1.UserCode,t1.Name from SYS_USER t1 inner join SYS_Office t2 on t1.OfficeId=t2.Id",
 (d,u, o) => u.UserCode.StartsWith("chen") && o.Name.Length>4);

3.UnitTest result