retrieving audit history using Z.EntityFramework.Plus.AuditExtensions.Where in DB first?


I'm using Z.EntityFramework.Plus package to implement the audit feature in my project; I'm following the DB first approach, I run the query that created the two audit tables as described here: by updating the .edmx file I got those new DBsets

public virtual DbSet<AuditEntries> AuditEntries { get; set; }
public virtual DbSet<AuditEntryProperties> AuditEntryProperties { get; set; }

now I want to retrieve the audit history, I use Where extension method in Z.EntityFramework.Plus namespace:

var auditlog = AuditExtensions.Where<TbAdditions>(oContext.AuditEntries, id).ToList();

but the compiler is yelling out at me, that he can't cast the DBset<AuditEntry> to DBSet<AuditEntries> as in the Where definition it requires DbSet<AuditEntry>, not DbSet<AuditEntries>, should I change the name of the table?

Expert Answer

Disclaimer: I'm the owner of the project Entity Framework Plus

You are currently using DB first approach with custom class AuditEntries and AuditEntryProperties. So you are not using Code First with class AuditEntry and AuditEntryProperty provided by Z.EntityFramework.Plus library.

The extension method has been made for the class provided by the library, so that's why it's incompatible with your class.

You will have to implement on your side the same extension methods found on this source: DbSet`AuditEntry.cs

Probably more extension methods will be required.

The Audit feature is supposed to be fully re-coded during the summer to allow more extensibility like this feature.

EDIT: Answer sub-question

How to implement it?

Here is an example how to implement it:

Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why