Coder Social home page Coder Social logo

sebbe33 / entityframeworkcore.manipulation.extensions Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 281 KB

Advanced data manipulation extensions for transactional upsert, sync, merge, and bulk insert in Entity Framework Core

License: MIT License

C# 100.00%
entityframework entityframeworkcore sql merge upsert

entityframeworkcore.manipulation.extensions's Introduction

EntityFrameworkCore.Manipulation.Extensions

Do you find yourself in a situation where you're in need of more advanced data manipulation operations than Entity Framework Core provides, such as Upsert or Merge/Sync? Then you've made it to the right place. This library providers extensions to Entity Framework core to support transactional upserts, inserts if not exist, and full syncs/merges. Additionally it provides you with the result of those operations, allowing you to see which entities were inserted, updated, and/or deleted.

Note: this library is currently in preview and the contract might change somewhat until the preview phase is completed.

Supported Databases (Providers)

Currently, this library supports the following databases:

  • SQL Server
  • SQLite

Getting Started

Install the latest version of the EntityFrameworkCore.Manipulation.Extensions through Nuget. No additional configuration is needed to get going, but there are several settings that can be tweaked to your needs (check them out below).

Here's an example of an Upsert (i.e. insert or update) of entities that are part of your DbContext, and a print-out of which entities got inserted or updated.

var entitiesToUpsert = new[] 
{
  new MyEntity { Id = "AlreadyExists", Value = "This is the new value" },
  new MyEntity { Id = "NewEntity", Value = "This is the new value" },
};
  

using var dbContext = new MyContext(); // get or instantiate your DbContext
var upsertResult = await dbContext.UpsertAsync(entitiesToUpsert);

Console.WriteLine($"The following entities were inserted: [{string.Join(',', upsertResult.InsertedEntities.Select(x => x.Id))}]");
Console.WriteLine($"The following entities were updated: [{string.Join(',', upsertResult.UpdatedEntities.Select(x => x.NewValue.Id))}]");

// The following entities were inserted: [NewEntity]
// The following entities were updated: [AlreadyExists] 

Contract

TODO

Configuration

TODO

entityframeworkcore.manipulation.extensions's People

Contributors

manio143 avatar muiriswoulfe avatar sebbe33 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

manio143

entityframeworkcore.manipulation.extensions's Issues

Clusivity not working when properties from base class are used for inclusion or exclusion while using derived entities.

Repro:
Define a BaseEntity class
And define a DerivedEntity : BaseEntity

And define exclusion or inclusion builder by specifying a property defined in BaseEntity while using EntityProvider

You get this error:

Message: 
    System.ArgumentException : The property TestBaseString could not be found in the DB schema
  Stack Trace: 
    <>c__DisplayClass0_0`1.<GetPropertiesFromExpressions>b__1(PropertyInfo propertyInfo)
    SelectListIterator`2.MoveNext()
    ConcatIterator`1.MoveNext()
    Set`1.UnionWith(IEnumerable`1 other)
    Enumerable.ExceptIterator[TSource](IEnumerable`1 first, IEnumerable`1 second, IEqualityComparer`1 comparer)+MoveNext()
    Set`1.UnionWith(IEnumerable`1 other)
    DistinctIterator`1.FillSet()
    DistinctIterator`1.ToArray()
    Enumerable.ToArray[TSource](IEnumerable`1 source)
    IClusivityBuilder<TEntity>.Build(IEnumerable`1 allAvailableProperties)
    SyncExtensions.SyncInternalAsync[TEntity](DbContext dbContext, IQueryable`1 target, IReadOnlyCollection`1 source, Boolean ignoreUpdates, Boolean ignoreDeletions, IClusivityBuilder`1 insertClusivityBuilder, IClusivityBuilder`1 updateClusivityBuilder, CancellationToken cancellationToken)
    SyncExtensions.UpsertAsync[TEntity](DbContext dbContext, IReadOnlyCollection`1 source, IClusivityBuilder`1 insertClusivityBuilder, IClusivityBuilder`1 updateClusivityBuilder, CancellationToken cancellationToken)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.