DapRepo
Dapper Generic Repository And Unit Of Work
Install / Use
/learn @mehrdadbahrainy/DapRepoREADME
DapRepo
Dapper Generic Repository And Unit Of Work
Instalation
Last Release: Version 1.1.0 (September 27, 2017)
PM> Install-Package Hurdad.DataAccess.DapRepo
Usage
Create models:
public class Person
{
[Key]
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
[Ignore]
public string FullName => $"{FirstName} {LastName}";
}
Create repository:
class PersonRepository : GenericRepository<Person>
{
public PersonRepository(IDbConnection dbConnection) : base(dbConnection)
{
}
}
Create unit-of-work class:
class AppUnitOfWork : UnitOfWork
{
public UnitOfWork(bool isTransactional = false,
IsolationLevel isolationLevel = IsolationLevel.ReadCommitted,
int transactionTimeoutInSecond = 300,
TransactionScopeOption transactionScopeOption = TransactionScopeOption.Required)
:base(isTransactional, isolationLevel, transactionTimeoutInSecond, transactionScopeOption)
{
}
protected override IDbConnection CreateConnection()
{
var connection = new System.Data.SqlClient.SqlConnection(connectionString: ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
return connection;
}
private PersonRepository _personRepository;
public PersonRepository PersonRepository => _personRepository ?? (_personRepository = new PersonRepository(this.DbConnection));
}
Then you can use instance of Unit-of-work class in your project:
using (var uow = new UnitOfWork(isTransactional: true))
{
uow.PersonRepository.Insert(person);
uow.CommitTransaction();
persons.AddRange(uow.PersonRepository.GetAll());
}
You can find full example project in sample directory
Related Skills
node-connect
342.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.7kCommit, push, and open a PR
