Skip to content

Commit 1863c4a

Browse files
authored
(#215) Docs for MySQL (#223)
1 parent b7b68ff commit 1863c4a

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

docs/content/in-depth/server/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Default repository implementations are provided for Entity Framework Core, LiteD
2323
* [Azure SQL and SQL Server](./databases/azuresql.md)
2424
* [In Memory Datastore](./databases/in-memory.md)
2525
* [LiteDb](./databases/litedb.md)
26+
* [MySQL](./databases/mysql.md)
2627
* [PostgreSQL](./databases/postgresql.md)
2728
* [Sqlite](./databases/sqlite.md)
2829

docs/content/in-depth/server/databases/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ For specific database support, see the following:
1515
* [Azure SQL and SQL Server](./azuresql.md)
1616
* [In Memory Datastore](./in-memory.md)
1717
* [LiteDb](./litedb.md)
18+
* [MySQL](./mysql.md)
1819
* [PostgreSQL](./postgresql.md)
1920
* [Sqlite](./sqlite.md)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
+++
2+
title = "MySQL"
3+
+++
4+
5+
## MySQL
6+
7+
Add the [`Pomelo.EntityFrameworkCore.Mysql`](https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql) driver to your project.
8+
9+
> [!INFO]
10+
> You can probably use the `MySql.EntityFrameworkCore` library as well. However, we only test with the Pomelo driver.
11+
12+
In the `OnModelCreating()` method of your context, add the following for each entity:
13+
14+
```csharp
15+
protected override void OnModelCreating(ModelBuilder modelBuilder)
16+
{
17+
modelBuilder.Entity<Model>().Property(m => m.UpdatedAt)
18+
.ValueGeneratedOnAddOrUpdate();
19+
20+
modelBuilder.Entity<Model>().Property(m => m.Version)
21+
.IsRowVersion();
22+
23+
base.OnModelCreating(modelBuilder);
24+
}
25+
```
26+
27+
* [Test MySQL Context](https://github.com/CommunityToolkit/Datasync/blob/main/tests/CommunityToolkit.Datasync.TestCommon/Databases/MySQL/MysqlDbContext.cs)

0 commit comments

Comments
 (0)