Last active
May 31, 2019 08:03
-
-
Save mikependon/e8b6a19558400af3e895ab98bbd4c53a to your computer and use it in GitHub Desktop.
IDbConnection (Query<Person>)
This file contains 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 characters
// Query | |
using (var connection = new SqlConnection(connectionString)) | |
{ | |
var person = connection.Query<Person>(p => p.Id == 10045).First(); | |
} | |
// Insert | |
using (var connection = new SqlConnection(connectionString)) | |
{ | |
var person = new Person | |
{ | |
FirstName = "John", | |
LastName = "Smith", | |
LastUpdatedUtc = DateTime.UtcNow, | |
CreatedDateUtc = DateTime.UtcNow | |
}; | |
var personId = connection.Insert(person); | |
} | |
// Update | |
using (var connection = new SqlConnection(connectionString)) | |
{ | |
var person = connection.Query<Person>(p => p.Id == 10045).First(); | |
person.FirstName = "John (Updated)"; | |
person.LastName = "Smith (Updated)"; | |
person.LastUpdatedUtc = DateTime.UtcNow; | |
var updatedRows = connection.Update(person); | |
} | |
// Delete | |
using (var connection = new SqlConnection(connectionString)) | |
{ | |
var deletedRows = connection.Delete<Person>(p => p.Id == 10045); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment