Skip to content
FlexLabs.Upsert is a library that brings UPSERT functionality to common database providers for Entity Framework in their respective native SQL syntax
Branch: develop
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
certs + Adding CI/CD process, code signing, package signing and SourceLink … Jun 24, 2018
src/FlexLabs.EntityFrameworkCore.Upsert
test/FlexLabs.EntityFrameworkCore.Upsert.Tests ! Nullable composite key should include all rows in the index (closes #… Feb 21, 2019
.editorconfig + Updating the editorconfig rules Sep 15, 2018
.gitattributes
.gitignore Add .gitignore and .gitattributes. Feb 16, 2018
FlexLabs.Upsert.sln + Adding a CI build file for pull requests Sep 3, 2018
LICENSE ! Patched the crash when using `.On()` with a single column Mar 10, 2018
README.md * Update the README Sep 19, 2018
appveyor.signed.bak.yml * Temporary switch to non signed build for MyGet Mar 17, 2019
appveyor.signed.yml
appveyor.yml * Swap the appveyor files to make it work by default on forks Sep 28, 2018

README.md

FlexLabs.Upsert

Build status FlexLabs.EntityFrameworkCore.Upsert on NuGet
CI build: FlexLabs.EntityFrameworkCore.Upsert on MyGet

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:

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 page for more examples

You can’t perform that action at this time.