Skip to content

Instantly share code, notes, and snippets.

View mikependon's full-sized avatar
Stop, do not knock! I am busy with RepoDB!

Michael Camara Pendon mikependon

Stop, do not knock! I am busy with RepoDB!
View GitHub Profile
@mikependon
mikependon / gist:57ce9af73b5a3cf8302b413fa0652997
Created July 22, 2020 08:07 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@mikependon
mikependon / ORM_Insert.cs
Created July 19, 2020 14:06
ORM_Insert.cs
using (var connection = new SqlConnection(connectionString))
{
return connection.Insert<Customer, int>(customer);
}
@mikependon
mikependon / ADO_Insert.cs
Last active July 19, 2020 14:06
ADO_Insert
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = "INSERT INTO [dbo].[Customer](Name, ..., CreatedDateUtc) VALUES (@Name, ..., @CreatedDateUtc); SELECT SCOPE_IDENTITY();";
command.Parameters.AddWithValue("@Name", customer.Name);
...
command.Parameters.AddWithValue("@CreatedDateUtc", customer.CreatedDateUtc);
return (int)command.ExecuteScalar();
using (var connection = new SqlConnection(connectionString))
{
return connection.QueryAll<Customer>();
}
@mikependon
mikependon / ADO_Query.cs
Created July 19, 2020 14:03
ADO_Query.cs
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT Id, Name, ... FROM [dbo].[Customer];";
var list = new List<Customer>();
using (reader = command.ExecuteReader())
{
var customer = new Customer
@mikependon
mikependon / RepoDb_ExecuteQuery_BulkInsert_Combination.cs
Created July 10, 2020 12:44
RepoDb_ExecuteQuery_BulkInsert_Combination
// Source from PostgreSQL
using (var sourceConnection = new NpgqlConnection(connectionStringToPostgreSQL))
{
var sales = sourceConnection.QueryAll<Sale>(e => e.OrderDate >= 'FromDate' && e.OrderDate <= 'ToDate');
// Destination to SQL Server
using (var destinationConnection = new SqlConnection(connectionStringToSqlServer))
{
destinationConnection.BulkInsert<Sale>(sales);
}
@mikependon
mikependon / RepoDb_Multiple_DataSources.cs
Created July 10, 2020 12:34
RepoDb_Multiple_DataSources.cs
// SqlConnection
using (var connection = new SqlConnection(connectionStringToSqlServer))
{
var customers = connection.QueryAll<Customer>();
}
// PostgreSQL
using (var connection = new NpgqlConnection(connectionStringToPostgreSQL))
{
var sales = connection.QueryAll<Sale>();
@mikependon
mikependon / RepoDb_Query_Cache_Filtered.cs
Last active July 10, 2020 11:53
RepoDb_Query_Cache_Filtered
/* SqConnection */
var cache = CacheFactory.GetCache(); // new MemoryCache();
using (var connection = new SqlConnection(connectionString).EnsureOpen())
{
var expirationInMinutes = 60 * 24; // 1 day
var products = connection.Query<Product>(e => e.CustomerId == customerId,
cacheKey: $"Customer-Product-{customerId}",
cacheItemExpiration: expirationInMinutes,
cache: cache);
}
@mikependon
mikependon / EF_RawSql_Indirect.cs
Created July 10, 2020 11:19
EF_RawSql_Indirect
using (var context = new DatabaseContext())
{
var customers = context
.People
.FromSqlRaw("SELECT * FROM [dbo].[Customer];");
}
@mikependon
mikependon / EF_RawSql_Direct.cs
Created July 10, 2020 11:18
EF_RawSql_Direct
using (var context = new DatabaseContext())
{
var customers = context
.People
.FromSqlRaw("SELECT * FROM [dbo].[Person];");
}