Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hamedstack/hamedstack.dapper
A library enhancing Dapper with additional utilities, type handlers, and features for improved data access performance and convenience, making Dapper more powerful for developers.
https://github.com/hamedstack/hamedstack.dapper
csharp csharp-library dapper database dotnet dotnet-core dotnetcore infrastructure repository typehandler utilities utility utility-library
Last synced: 27 days ago
JSON representation
A library enhancing Dapper with additional utilities, type handlers, and features for improved data access performance and convenience, making Dapper more powerful for developers.
- Host: GitHub
- URL: https://github.com/hamedstack/hamedstack.dapper
- Owner: HamedStack
- License: mit
- Created: 2024-03-21T09:37:12.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-10-05T08:48:01.000Z (about 1 month ago)
- Last Synced: 2024-10-12T14:21:15.644Z (27 days ago)
- Topics: csharp, csharp-library, dapper, database, dotnet, dotnet-core, dotnetcore, infrastructure, repository, typehandler, utilities, utility, utility-library
- Language: C#
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Usage Guide
### 1. Registering Type Handlers
Before you start using `DateOnly` and `TimeOnly` in your Dapper queries or commands, you need to register the type handlers. This is a one-time setup that should be called before any database operation.#### Add Type Handlers
```csharp
using HamedStack.Dapper;// Register type handlers at the start of the application
SqlMapperTypeHandler.AddDateOnlyTimeOnlyTypeHandlers();
```### 2. Using `DateOnly` and `TimeOnly` in Dapper Queries
Once the type handlers are registered, you can use `DateOnly` and `TimeOnly` types directly in your Dapper queries as parameters or for mapping results.#### Example: Inserting `DateOnly` and `TimeOnly` Values
```csharp
using Dapper;
using System.Data.SqlClient;string connectionString = "your_connection_string";
using var connection = new SqlConnection(connectionString);
connection.Open();var date = new DateOnly(2023, 10, 05); // DateOnly value
var time = new TimeOnly(14, 30, 0); // TimeOnly valuestring sql = "INSERT INTO YourTable (DateColumn, TimeColumn) VALUES (@Date, @Time)";
connection.Execute(sql, new { Date = date, Time = time });
```#### Example: Querying and Mapping to `DateOnly` and `TimeOnly`
```csharp
string query = "SELECT DateColumn, TimeColumn FROM YourTable WHERE Id = @Id";var result = connection.QuerySingleOrDefault(query, new { Id = 1 });
DateOnly dateResult = result.DateColumn;
TimeOnly timeResult = result.TimeColumn;
```