Skip to content

A library enhancing Dapper with additional utilities, type handlers, and features for improved data access performance and convenience, making Dapper more powerful for developers.

License

Notifications You must be signed in to change notification settings

HamedStack/HamedStack.Dapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

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 value

string 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

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;

About

A library enhancing Dapper with additional utilities, type handlers, and features for improved data access performance and convenience, making Dapper more powerful for developers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages