My application uses Audit.NET
with Audit.EntityFramework
for audit logging data changes. For the purpose of facilitation the creation of audit log / data changes visualisation, I decided to log changes from a few tables into a single one. Long story short: I defined a state machine for my item and I'm logging whats happening with it from when it first appears in my system till when I dispose it.
In order to demonstrate the issues that I'm struggling with, I create a test REST app and made it available on GitHub repository.
The application tracks the lifetime of articles, where an article can come to the system by:
- an article is directly added and linked to a publication - in short, it is ACCEPTED
- an article proposal is added - in short, it is PROPOSED
- a PROPOSED article can be accepted for addition to a publication - in short, it is ACCEPT_PROPOSAL
For some more details, check the public enum ProcessAction
.
How to reproduce
- Clone the repo
- Create the DB and the user - creation SQL code is contained in a comment in
TestDbContext.cs
- Run the DB migration
- Start the application
- Call all endpoints from
TestsController.cs
in the order they appear - here are direct links (HTTP GET
):- Mew Publication: http://localhost:5000/tests/publication/add?name=New%20Publication
- Add Article: http://localhost:5000/tests/article/add?type=ReviewArticle&title=Test%20article%202018¬e=My%20test%20note&publicationId=1
- Propose an article: http://localhost:5000/tests/proposal/add?type=ReviewArticle&title=Test proposal 1¬e=Proposal%20note%201
- Accept the article proposal (NOTE: the article ID may differ on your system): http://localhost:5000/tests/accept/1?publicationId=2
Issues
The last call is throwing the following exception:
InvalidCastException: Unable to cast object of type 'si.dezo.test.DotNetAudit.Models.Article' to type 'si.dezo.test.DotNetAudit.Models.ArticleProposal'.
I commented out a few lines of code in
TestDbContext.cs
and marked it asNOTE: the below is not working
Am I doing something wrong or is it a limitation or a bug of the library?
Is there a way around the issue?