Created
February 14, 2012 19:28
-
-
Save lancscoder/1829462 to your computer and use it in GitHub Desktop.
Revisions
-
lancscoder revised this gist
Feb 18, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // Dapper - Single using (var connection = MvcApplication.GetOpenConnection()) { var post = connection.Query<Post>("select * from posts where id = @id", new { id = 1 }).First(); } -
lancscoder revised this gist
Feb 14, 2012 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ return new MvcMiniProfiler.Data.ProfiledDbConnection(connection, MiniProfiler.Current); -
lancscoder created this gist
Feb 14, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ public class ConnectionFactory { public static DbConnection GetOpenConnection() { var connection = new SqlConnection("MyConnectionString"); connection.Open(); return connection; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ // Dapper - Delete using (var connection = MvcApplication.GetOpenConnection()) { connection.Execute(@"delete from Posts where id = @id", new { id = 1 }); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ // Dapper – Filtered List using (var connection = ConnectionFactory.GetOpenConnection()) { var posts = connection.Query<Post>("select * from posts where text like @text", new { text = "%Some Value%" }).ToList(); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ // Dapper - Insert using (var connection = MvcApplication.GetOpenConnection()) { var post = new Post { Title = "Title 1", Text = "Text 1", PublishDate = DateTime.Now }; post.ID = connection.Query<int>(@"insert into Posts(Title, Text, PublishDate) values (@Title, @Text, @PublishDate); select cast(scope_identity() as int)", new { post.Title, post.Text, post.PublishDate }).First(); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ // Dapper Insert Using SQL Compact Edition using (var connection = MvcApplication.GetOpenConnection()) { var post = new Post { Title = "Title 1", Text = "Text 1", PublishDate = DateTime.Now }; connection.Execute(@"insert into Posts(Title, Text, PublishDate) values (@Title, @Text, @PublishDate);", new { post.Title, post.Text, post.PublishDate }); post.ID = (int)connection.Query(@"select @@IDENTITY as ID").First().ID; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ // Dapper – Simple List using (var connection = ConnectionFactory.GetOpenConnection()) { var posts = connection.Query<Post>("select * from posts").ToList(); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ // Dapper - Single using (var connection = MvcApplication.GetOpenConnection()) { var post = connection.Query<Post("select * from posts where id = @id", new { id = 1 }).First(); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ // Dapper - Update using (var connection = MvcApplication.GetOpenConnection()) { var post = connection.Query<Post>( "select * from posts where id = @id", new { id = 1 } ).First(); post.Title = "New Title"; connection.Execute(@"update Posts set Title = @Title, Text = @Text, PublishDate = @PublishDate where ID = @id;", new { post.ID, post.Title, post.Text, post.PublishDate }); }