Giter Club home page Giter Club logo

entityframeworkcore.temporaltables's Introduction

EntityFrameworkCore.TemporalTables

Extension library for Entity Framework Core which allows developers who use SQL Server to easily use temporal tables.

How to use it?

Service Provider configuration

  1. Use UseInternalServiceProvider() on DbContextOptionsBuilder when registering your DbContext to replace Entity Framework's internal service provider with yours. For example:
services.AddDbContextPool<MyDbContext>((provider, options) =>
{
    options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"));
    options.UseInternalServiceProvider(provider);
});
  1. Then register all Entity Framework services into your service provider by using: services.AddEntityFrameworkSqlServer();

  2. And finally call: services.RegisterTemporalTablesForDatabase<MyDbContext>();

Use the first two settings only when you want your temporal tables to be executed by default when using Update-Database command from Package Manager Console or DbContext.Database.Migrate() / DbContext.Database.MigrateAsync().

If you want to handle the temporal tables SQL execution yourself, you can do it manually by using:

var temporalTableSqlExecutor = serviceProvider.GetService<ITemporalTableSqlExecutor<MyDbContext>>();
temporalTableSqlExecutor.Execute();

DbContext configuration

In OnModelCreating(ModelBuilder modelBuilder) method you have the following options:

  • modelBuilder.UseTemporalTables() - create temporal table for all of your entities by default.

  • modelBuilder.PreventTemporalTables() - do not create temporal table for none of your entities by default.

  • modelBuilder.Entity<TEntity>(b => b.UseTemporalTable()); - create a temporal table for the specified entity TEntity. This method is compatible with UseTemporalTables() and PreventTemporalTables() methods - e.g. you can call PreventTemporalTables() and then only register the entities you want.

  • modelBuilder.Entity<TEntity>(b => b.PreventTemporalTable()); - do not create a temporal table for the specified entity TEntity. This method is also compatible with UseTemporalTables() and PreventTemporalTables() methods.


You can refer to the sample application for more configuration information.

You can install the NuGet package from here: https://www.nuget.org/packages/EntityFrameworkCore.TemporalTables/

entityframeworkcore.temporaltables's People

Contributors

findulov avatar

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.