How To
How to Get all classes with a custom attribute in C#
By Tan Lee Published on Mar 12, 2025 357
To find all classes with a custom attribute, the first step is to gather all types within the assembly and then use the IsDefined method to filter the types that are marked with the custom attribute.
How to Map query results to multiple objects with Dapper in C#
By Tan Lee Published on Mar 12, 2025 526
When dealing with SQL queries that join multiple tables, Dapper's multi-mapping feature allows you to map the results to multiple objects. This can be really handy when you're pulling related data in a single query.
How to Update appsettings.json in C#
By Tan Lee Published on Mar 06, 2025 674
To update values programmatically within a settings JSON file, you will need to overwrite the entire settings.json file.
Injecting ILogger into Dapper Polly Retry Policy in C#
By Tan Lee Published on Mar 11, 2025 365
To inject ILogger into a Dapper Polly Retry Policy in C#, you can follow these steps.
Properly Disposing HttpContent When Using HttpClient in C#
By Tan Lee Published on Mar 11, 2025 304
In versions prior to .NET Core 3.0 (including .NET Framework), database connection pooling was automatically managed by the framework, with the connection object being disposed of at the end of each operation.
How to send a file with HttpClient in C#
By Tan Lee Published on Mar 11, 2025 610
When uploading a file with HttpClient, you need to place the file inside a MultipartFormDataContent object, which will be sent as the body of the HTTP request.
How to Deserialize JSON with quoted numbers in C#
By Tan Lee Published on Mar 11, 2025 410
In JSON, numbers can be represented in two main formats: as literal numbers (e.g., 123) or as quoted strings (e.g., "123").
How to Configure HttpClient connection keep-alive in C#
By Tan Lee Published on Mar 11, 2025 603
When using a single instance of SqlConnection to interact with a database, the connection is pooled, meaning it can be reused for subsequent requests to improve performance.
Performance Benefits of Reusing Connections with HttpClient
By Tan Lee Published on Mar 11, 2025 228
To demonstrate the performance gains of keeping a database connection open and reusing it across multiple queries, I’ll perform multiple database queries to the same database.
How to add request headers when using HttpClient in C#
By Tan Lee Published on Mar 11, 2025 553
When using HttpClient to send requests in C#, there are two primary ways to add headers:
How to Delete records with Dapper in C#
By Tan Lee Published on Mar 10, 2025 342
In C#, you can use Dapper to delete records from a database by executing a DELETE statement with the Execute() method, passing in the record identifier as a parameter.
How to Execute a SELECT query with Dapper in C#
By Tan Lee Published on Mar 10, 2025 401
You can query a database in C# using Dapper by executing a SELECT query with the Query() method, specifying the type to map the results to, and optionally adding parameters.