* Dapper [#u8e246a9]


** dynamic型に結果を詰める [#v607c46e]
 var dsn = "Server=hv-cent01;Port=5432;User Id=taro;Password=mypass;Database=mydb";
 var cn = new NpgsqlConnection(dsn);
 cn.Open();
 var all = cn.Query(@"SELECT * FROM t1");

** 型を指定して結果を詰める [#t9b6b4b3]
 var all = cn.Query<MyEntity>(@"SELECT * FROM t1");
 
 public class MyEntity
 {
     public int Id { get; set; }
     public string Name { get; set; }
 }


 IEnumerable<UserEntity> users;
 using (var cn = new NpgsqlConnection(dsn))
 {
     cn.Open();
     users = cn.Query<UserEntity>(@"SELECT * FROM user WHERE name LIKE @name LIMIT 10",
         new { name = '%' + name + '%'});
 }

** オフィシャル [#e215a594]
- http://code.google.com/p/dapper-dot-net/
*** テストコード [#cfea6b38]
- https://github.com/SamSaffron/dapper-dot-net/blob/master/Tests/Tests.cs

** プリペアドステートメントでのLIKE演算子 [#nd198e29]
- http://stackoverflow.com/questions/10563077/dapper-like-query-for-mysql-safe-against-sql-injection?rq=1

** 参考 [#fe2d33af]
- http://kiyokura.hateblo.jp/entry/20131014/p1
-- http://www.slideshare.net/kiyokura/adonetormmicro-orm-dapper-dot-net

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS