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

entity-framework entity-framework-plus


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?

7/10/2017 7:06:48 AM

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:

7/10/2017 11:47:56 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow