update PersonsetAge =@Agewhere Name = @Nameand Sex = @Sexpublic class Person{public int Id { get; set; }public string Name { get; set; }public int Age { get; set; }public int Sex { get; set; }}こんな感じになったら嬉しい
public sealed classSequenceMappingInfo{public string Schema { get; } //--- シーケンスのスキーマ名public string Name { get; } //--- シーケンス名}マッピングメタデータの提供 #3
18.
//--- 指定の列のみを対象として全レコード取得var sql= PrimitiveSql.CreateSelect<Person>(x => x.Id, x => x.Name);/*selectId as Id,名前 as Namefrom dbo.Person*/プリミティブなSQLの生成 #1指定がない場合は全列が対象
//--- 全件取得var p1= connection.Select<Person>();//--- Id, Name 列に絞って全件取得var p2 = connection.Select<Person>(x => x.Id, x => x.Name);//--- Id = 3 のレコードのみ取得var p3 = connection.Select<Person>(x => x.Id == 3);//--- Id > 3 のレコードを Id, Name 列に絞って取得var p4 = connection.Select<Person>(x => x.Id > 3, x => x.Id, x => x.Name);レコードの取得.Select<T>
22.
//--- 指定されたデータを挿入var p5= connection.Insert(new Person { Name = "xin9le", Age = 30 });//--- 複数のレコードでもOKvar p6 = connection.Insert(new []{new Person { Name = "yoshiki", Age= 49, },new Person { Name = "suzuki", Age= 30, },new Person { Name = "anders", Age= 54, },});レコード挿入.Insert<T>
23.
//--- Age =30 のレコードの Name 列を更新var p7 = connection.Update(new Person { Name = “xin9le" },x => x.Age == 30, //--- 指定しなければ全レコード更新x => x.Name //--- 指定がなければ全列更新);レコード更新.Update<T>
//--- メソッド名に ‘Async’を付けるだけvar p1 = await connection.SelectAsync<Person>();var p2 = await connection.InsertAsync(new Person { Name = "xin9le" });var p3 = await connection.UpdateAsync(new Person { Name = "xin9le" });var p4 = await connection.DeleteAsync<Person>();もちろん非同期版も実際に非同期処理になるかは各DBプロバイダーに依存する
26.
Simple = Speed+ PowerDapperの強みをそのままに、select * などの決まった手間を軽減たった1文で書けるDBアクセスサポートしていない構文inner join / left join / order by / group by / サブクエリー (etc.)やり過ぎは複雑さの増大と自由度の低下を招くシンプルに、そしてカジュアルに