question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can EntityHistory track properties across DbContexts?

See original GitHub issue

Documentation

Please check the official documentation before asking questions: https://aspnetboilerplate.com/Pages/Documents

GitHub Issues

GitHub issues are for bug reports, feature requests and other discussions about the framework.

If you’re creating a bug/problem report, please include followings:

  • Your Abp package version: 4.11.0 (.netcore 3.0 prevents me from going to 5.0 (damn client side evals…))
  • Your base framework: .Net Core.
  • Exception message and stack trace if available.
  • Steps needed to reproduce the problem.

I have generated a template project and configured to use multiple DbContexts using an (out of date) sample provided by ABP here.

I’ve followed the docs for implementing entity history and was successfully able to audit PortalDbContext.Users email property changes. So far so good!

In SecondDbContext, Table1 inherits from IFullAudited and I would like to track property changes for this table. I did everything I did with the Users table to Table1 but I am unable to get any records in EntityPropertyChanges, EntityChangeSets or EntityChanges.

After a few hours of trying a bunch of different things, I decided to move Table1 from SecondDbContext to PortalDbContext and after trying again, I finally got some records to show up in the EntityChanges tables.

It would seem that either tracking Property Changes is not supported on entities NOT on the same DbContexts as the ‘EntityChanges’ table OR there is additional configurations required that not in the docs.

I am working on attaching a reproducible project. May need an hour to split into a separate project.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ryancyqcommented, Jan 15, 2020

@multinerd does your second dbcontext inherits from AbpZeroCommonDbContext?

Otherwise, you will need to either

  • customize IEntityHistoryStore to save entity history into EntityChanges table via first dbcontext as mentioned by @maliming
  • add EntityChanges to second dbcontext and invoke IEntityHistoryHelper.CreateEntityChangeSet and IEntityHistoryHelper.SaveAsync in your second dbcontext’s SaveChangesAsyncmethod
0reactions
ryancyqcommented, Jan 15, 2020

@multinerd when seeing Zero in the context of Abp, it is always referring to module zero , see https://aspnetboilerplate.com/Pages/Documents/Zero/Overall

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accessing Tracked Entities - EF Core
An entity that becomes tracked by the DbContext will automatically appear in the DbSet.Local collection. For example, executing a query to bring ...
Read more >
c# - Navigation property from another DbContext
I have a request to divide one DbContext to multiple DbContexts with separate entites, but before going into it, I want to know...
Read more >
Allow entity instances to be tracked by two bounded ...
Ask a question I am using bounded contexts. This means I have two different DbContexts, with their own entities, and own "Schema", ...
Read more >
Entity history when using multiple db contexts #10796
Hi, yes, our DbContexts inherit from AbpDbContext.
Read more >
Managing DbContext the right way with Entity Framework 6
A DbContext instance can however span across multiple (sequential) business transactions. Once a business transaction has completed and has ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found