arch / AutoHistory

A plugin for Microsoft.EntityFrameworkCore to support automatically recording data changes history.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AutoHistory is not working with PostgreSQL

attiqeurrehman opened this issue · comments

Hi,

The AutoHistory table is created in the database but there are no records.

My config is:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    // enable auto history functionality, 22023 is max limit supported by PostgreSQL
    modelBuilder.EnableAutoHistory(22023);
}

and during any save or update I am using the following:

await UnitOfWork.SaveChangesAsync(true);

Further technical details

EF Core version: 2.0.1
Database Provider: Npgsql.EntityFrameworkCore.PostgreSQL
Operating system: Windows 10
IDE: Visual Studio Enterprise 2017 15.4.5

Please give me more about debugging info.

@attiqeurrehman just a question? Did you write this code before the saving changes: dbContext.EnsureAutoHistory()?

@alexmtnezf I am using UnitOfWork and using the following function:

// <summary>
        /// Asynchronously saves all changes made in this unit of work to the database.
        /// </summary>
        /// <param name="ensureAutoHistory"><c>True</c> if save changes ensure auto record the change history.</param>
        /// <returns>A <see cref="Task{TResult}"/> that represents the asynchronous save operation. The task result contains the number of state entities written to database.</returns>
        public async Task<int> SaveChangesAsync(bool ensureAutoHistory = false)
        {
            if (ensureAutoHistory)
            {
                _context.EnsureAutoHistory();
            }

            return await _context.SaveChangesAsync();
        }

I am passing true for each Save.

await UnitOfWork.SaveChangesAsync(true);

@alexmtnezf Please install PostgreSQL and debugging for this issues, I'm too busy recently, thnaks

@attiqeurrehman I tested an ASP.NET Core project that I'm developing doing the following things:

  1. Installed the Npgsql nuget package and the extension for EFCore. (OK)
  2. Run migrations (OK)
  3. Run the project, saved an entity (nothing happened since AutoHistory doesn't support added entities), and finally I updated the same entity and voila ( there are records in AutoHistory table).

@alexmtnezf Good job, thanks!

Close because not more info