Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/artiomchi/FlexLabs.Upsert
FlexLabs.Upsert is a library that brings UPSERT functionality to common database providers for Entity Framework in their respective native SQL syntax
https://github.com/artiomchi/FlexLabs.Upsert
Last synced: 3 months ago
JSON representation
FlexLabs.Upsert is a library that brings UPSERT functionality to common database providers for Entity Framework in their respective native SQL syntax
- Host: GitHub
- URL: https://github.com/artiomchi/FlexLabs.Upsert
- Owner: artiomchi
- License: mit
- Created: 2018-02-17T00:07:46.000Z (over 6 years ago)
- Default Branch: develop
- Last Pushed: 2024-04-02T10:22:51.000Z (8 months ago)
- Last Synced: 2024-07-30T13:40:57.165Z (4 months ago)
- Language: C#
- Homepage:
- Size: 1.56 MB
- Stars: 519
- Watchers: 16
- Forks: 81
- Open Issues: 46
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-entity-framework-core - FlexLabs.Upsert - Brings UPSERT functionality to common database providers for Entity Framework in their respective native SQL syntax. (Supported Packages / Contents)
README
FlexLabs.Upsert
==========[![Build status](https://ci.appveyor.com/api/projects/status/a64hu4iyx7r4a3yo?svg=true)](https://ci.appveyor.com/project/artiomchi/flexlabs-upsert)
[![FlexLabs.EntityFrameworkCore.Upsert on NuGet](https://img.shields.io/nuget/v/FlexLabs.EntityFrameworkCore.Upsert.svg)](https://www.nuget.org/packages/FlexLabs.EntityFrameworkCore.Upsert)
CI build: [![FlexLabs.EntityFrameworkCore.Upsert on MyGet](https://img.shields.io/myget/artiomchi/vpre/FlexLabs.EntityFrameworkCore.Upsert.svg)](https://github.com/artiomchi/FlexLabs.Upsert/wiki/CI-Builds)This library adds basic support for "Upsert" operations to EF Core.
Uses `INSERT … ON CONFLICT DO UPDATE` in PostgreSQL/Sqlite, `MERGE` in SqlServer and `INSERT INTO … ON DUPLICATE KEY UPDATE` in MySQL.
Also supports injecting sql command runners to add support for other providers
A typical upsert command could look something like this:
```csharp
DataContext.DailyVisits
.Upsert(new DailyVisit
{
UserID = userID,
Date = DateTime.UtcNow.Date,
Visits = 1,
})
.On(v => new { v.UserID, v.Date })
.WhenMatched(v => new DailyVisit
{
Visits = v.Visits + 1,
})
.RunAsync();
```In this case, the upsert command will ensure that a new `DailyVisit` will be added to the database. If a visit with the same `UserID` and `Date` already exists, it will be updated by incrementing it's `Visits` value by 1.
Please read our [Usage](https://github.com/artiomchi/FlexLabs.Upsert/wiki/Usage) page for more examples