Skip to content

Commit 5aff25b

Browse files
Add MicroOrm.Dapper.Repositories in Extensions list
1 parent d9c8aed commit 5aff25b

File tree

4 files changed

+215
-2
lines changed

4 files changed

+215
-2
lines changed

learndapper.com/pages/dapper-and-dapper-plus.md

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ We’ve been in contact (since mid-April 2025) with four NuGet library owners to
7171

7272
So yes, Dapper Plus is directly connected to Dapper by giving back to those who actively contribute to this awesome library.
7373

74+
- [Dapper.Extensions.NetCore](https://www.learndapper.com/extensions/dapper-extensions): $150 USD monthly
75+
- [MicroOrm.Dapper.Repositories](#): $150 USD monthly
76+
7477
---
7578

7679
### 💡 Mindset

learndapper.com/pages/extensions/index.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Extensions for EF Core | Third Party Libraries
33
description: An introduction to third-party libraries for EF Core
44
canonical: /extensions
55
status: Published
6-
lastmod: 2025-04-05
6+
lastmod: 2025-04-21
77
---
88

99
# Extensions
@@ -22,4 +22,10 @@ A dapper extension library.
2222
4. Support reading and writing separation.
2323
5. Support performance monitoring.
2424

25-
[Read more](/extensions/dapper-extensions)
25+
[Read more](/extensions/dapper-extensions)
26+
27+
## MicroOrm.Dapper.Repositories
28+
29+
MicroOrm.Dapper.Repositories is a lightweight library that extends Dapper by generating SQL for CRUD operations based on your POCO classes. It simplifies data access by using metadata attributes to build queries automatically, including support for joins, logical deletes, and pagination.
30+
31+
[Read more](/extensions/microorm-dapper-repositories)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
---
2+
title: MicroOrm.Dapper.Repositories
3+
description: An introduction to MicroOrm.Dapper.Repositories
4+
canonical: /extensions/microorm-dapper-repositories
5+
status: Published
6+
lastmod: 2025-04-21
7+
---
8+
9+
# MicroOrm.Dapper.Repositories
10+
11+
[![ci](https://img.shields.io/github/actions/workflow/status/phnx47/dapper-repositories/ci.yml?branch=main&label=ci&logo=github%20actions&logoColor=white&style=flat-square)](https://github.com/phnx47/dapper-repositories/actions/workflows/ci.yml)
12+
[![nuget](https://img.shields.io/nuget/v/MicroOrm.Dapper.Repositories?logo=nuget&style=flat-square)](https://www.nuget.org/packages/MicroOrm.Dapper.Repositories)
13+
[![nuget](https://img.shields.io/nuget/dt/MicroOrm.Dapper.Repositories?logo=nuget&style=flat-square)](https://www.nuget.org/packages/MicroOrm.Dapper.Repositories)
14+
[![codecov](https://img.shields.io/codecov/c/github/phnx47/dapper-repositories?logo=codecov&style=flat-square&token=wR4U6i4vhk)](https://codecov.io/gh/phnx47/dapper-repositories)
15+
[![license](https://img.shields.io/github/license/phnx47/dapper-repositories?style=flat-square)](https://github.com/phnx47/dapper-repositories/blob/main/LICENSE)
16+
17+
## Description
18+
19+
If you like your code to run fast, you probably know about Micro ORMs. They are simple and one of their main goals is to be the fastest execution of your SQL sentences in you data
20+
repository. For some Micro ORM's you need to write your own SQL sentences and this is the case of the most popular Micro
21+
ORM [Dapper](https://github.com/DapperLib/Dapper)
22+
23+
This tool abstracts the generation of the SQL sentence for CRUD operations based on each C# POCO class "metadata". We know there are plugins for both Micro ORMs that implement the
24+
execution of these tasks, but that's exactly where this tool is different. The "SQL Generator" is a generic component that generates all the CRUD sentences for a POCO class based
25+
on its definition and the possibility to override the SQL generator and the way it builds each sentence.
26+
27+
The original idea was taken from [Diego García](https://github.com/ElNinjaGaiden/Dapper.DataRepositories).
28+
29+
## Installation
30+
31+
```sh
32+
dotnet add package MicroOrm.Dapper.Repositories
33+
```
34+
35+
## Docs
36+
37+
### Metadata attributes
38+
39+
**[Key]**
40+
From `System.ComponentModel.DataAnnotations` - Use for primary key.
41+
42+
**[Identity]**
43+
Property with an automatically incrementing identification number.
44+
45+
**[Table]**
46+
From `System.ComponentModel.DataAnnotations.Schema` - By default the database table name will match the model name but it can be overridden with this.
47+
48+
**[Column]**
49+
From `System.ComponentModel.DataAnnotations.Schema` - By default the column name will match the property name but it can be overridden with this.
50+
51+
**[NotMapped]**
52+
From `System.ComponentModel.DataAnnotations.Schema` - For "logical" properties that do not have a corresponding column and have to be ignored by the SQL Generator.
53+
54+
**[Deleted], [Status]**
55+
For tables that implement "logical deletes" instead of physical deletes. Use this to decorate the `bool` or `enum`.
56+
57+
**[LeftJoin]**
58+
Left join for property: Collection and object are supported.
59+
60+
**[InnerJoin]**
61+
Inner join for property: Collection and object are supported.
62+
63+
**[RightJoin]**
64+
Right join for property: Collection and object are supported.
65+
66+
**[CrossJoin] - SQLite only**
67+
Cross join for property: Collection and object are supported.
68+
69+
**[UpdatedAt]**
70+
Automatically set DataTime.UtcNow (You can use local date or define offset) for Insert and Update.
71+
72+
### Notes
73+
74+
- By default the SQL Generator is going to map the POCO name with the table name, and each public property to a column.
75+
- If the [Deleted] is used on a certain POCO, the sentence will be an update instead of a delete.
76+
- Supports complex primary keys.
77+
- Supports simple Joins.
78+
- For this moment, with MSSQL you can only use limit with offset if you call OrderBy first, otherwise limit will be ignored.
79+
- It has a problem when try to use GUID with dapper in Oracle. In this case it doesn't work. Look details: [Dapper#633](https://github.com/DapperLib/Dapper/issues/633), [Dapper#637](https://github.com/DapperLib/Dapper/issues/637)
80+
81+
### Maps
82+
83+
"Users" POCO:
84+
85+
```c#
86+
[Table("Users")]
87+
public class User
88+
{
89+
[Key, Identity]
90+
public int Id { get; set; }
91+
92+
public string ReadOnly => "test"; // because don't have set
93+
94+
public string Name { get; set; }
95+
96+
public int AddressId { get; set; }
97+
98+
[LeftJoin("Cars", "Id", "UserId")]
99+
public List<Car> Cars { get; set; }
100+
101+
[LeftJoin("Addresses", "AddressId", "Id")]
102+
public Address Address { get; set; }
103+
104+
[Status, Deleted]
105+
public bool Deleted { get; set; }
106+
107+
[UpdatedAt]
108+
public DateTime? UpdatedAt { get; set; }
109+
}
110+
```
111+
112+
"Cars" POCO:
113+
114+
```c#
115+
[Table("Cars")]
116+
public class Car
117+
{
118+
[Key, Identity]
119+
public int Id { get; set; }
120+
121+
public string Name { get; set; }
122+
123+
public byte[] Data { get; set; }
124+
125+
public int UserId { get; set; }
126+
127+
[LeftJoin("Users", "UserId", "Id")]
128+
public User User { get; set; }
129+
130+
[Status]
131+
public StatusCar Status { get; set; }
132+
}
133+
134+
public enum StatusCar
135+
{
136+
Inactive = 0,
137+
138+
Active = 1,
139+
140+
[Deleted]
141+
Deleted = -1
142+
}
143+
```
144+
145+
Example Implements the simple repository:
146+
147+
```c#
148+
public class UserRepository : DapperRepository<User>
149+
{
150+
public UserRepository(IDbConnection connection, ISqlGenerator<User> sqlGenerator)
151+
: base(connection, sqlGenerator)
152+
{
153+
154+
}
155+
}
156+
```
157+
158+
### Queries
159+
160+
Find by ID:
161+
162+
```c#
163+
var user = await userRepository.FindAsync(x => x.Id == 5);
164+
```
165+
166+
Query with limit:
167+
168+
```c#
169+
var limit = 10u;
170+
var users = await userRepository.SetLimit(limit).FindAllAsync();
171+
```
172+
173+
Query with limit and offset:
174+
175+
```c#
176+
var limit = 10u;
177+
var offset = 5u;
178+
var users = await userRepository.SetLimit(limit, offset).FindAllAsync();
179+
```
180+
181+
Query with OrderBy:
182+
183+
```c#
184+
var users = await userRepository.SetOrderBy(OrderInfo.SortDirection.DESC, x => x.CreatedAt).FindAllAsync();
185+
```
186+
187+
Query with SetSelect:
188+
189+
```c#
190+
var users = await userRepository.SetSelect(x => new {x.Id, x.Name}).FindAllAsync();
191+
```
192+
193+
## Sponsors
194+
195+
[Dapper Plus](https://dapper-plus.net/) and [Entity Framework Extensions](https://entityframework-extensions.net/) are major sponsors and are proud to contribute to the development of MicroOrm.Dapper.Repositories
196+
197+
[![Dapper Plus](https://raw.githubusercontent.com/phnx47/dapper-repositories/main/dapper-plus-sponsor.png)](https://dapper-plus.net/bulk-insert)
198+
199+
[![Entity Framework Extensions](https://raw.githubusercontent.com/phnx47/dapper-repositories/main/entity-framework-extensions-sponsor.png)](https://entityframework-extensions.net/bulk-insert)
200+
201+
## License
202+
203+
All contents of this package are licensed under the [MIT license](https://opensource.org/licenses/MIT).

learndapper.com/pages/nav.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<li><a href="/extensions">Extensions</a>
2222
<ul class="nav-level-two">
2323
<li><a href="/extensions/dapper-extensions">Dapper.Extensions</a></li>
24+
<li><a href="/extensions/microorm-dapper-repositories">MicroOrm.Dapper.Repositories</a></li>
2425
</ul>
2526
</li>
2627

0 commit comments

Comments
 (0)