标签:
sql:
SELECT * FROM users; SELECT * FROM posts; SELECT * FROM Posts p LEFT JOIN Users u ON u.Id= p.OwnerId ORDER BY p.Id
结果集:
string sql =@"select * from Posts p left join Users u on u.Id = p.OwnerId Order by p.Id";
PostWithConstructor[] data = connection.Query<PostWithConstructor,UserWithConstructor,PostWithConstructor>(sql,(post, user)=>{ post.Owner= user;return post;}).ToArray();
publicstaticIEnumerable<TReturn>Query<TFirst,TSecond,TReturn>( #if CSHARP30 thisIDbConnection cnn,string sql,Func<TFirst,TSecond,TReturn>map,object param,IDbTransaction transaction, bool buffered,string splitOn,int? commandTimeout,CommandType? commandType #else thisIDbConnection cnn,string sql,Func<TFirst,TSecond,TReturn>map,object param =null,IDbTransaction transaction =null, bool buffered =true,string splitOn ="Id",int? commandTimeout =null,CommandType? commandType =null #endif )
(post, user)=>{ post.Owner= user;return post;}
Dapper使用方法:dapper-dot-net/Tests/Tests.cs解析(1)方法:TestMultiMapWithConstructor
标签:
原文地址:http://www.cnblogs.com/9527y/p/4769118.html