How to audit join tables with Audit.EntityFramework?
See original GitHub issueGiven the following example and configuration how do you log the join table operations?
They get ignored currently by the Entity Framework Auditing framework.
When you insert a new EventAvailabilityResponse into the database, and add a “EventLocation” into the PreferredEventLocations list in the model shown below only the Insert to the EventAvailabilityResponse table is captured.
I have tried IncludeEntityObjects = True but it is missing the EventLocation inserts into the join table “EventAvailabilityResponseEventLocations”
Model Classes:
public class EventAvailabilityResponse
{
public EventAvailabilityResponse()
{
EventAvailabilityResponseId = Guid.NewGuid().ToString();
}
[Key]
[StringLength(36)]
public string EventAvailabilityResponseId { get; set; }
[StringLength(4000)]
public string Comment { get; set; }
public virtual EventNotification EventNotification { get; set; }
public virtual List<EventLocation> PreferredEventLocations { get; set; }
}
public class EventLocation
{
public EventLocation()
{
Location = string.Empty;
}
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int EventLocationId { get; set; }
[Required]
public string Location { get; set; }
public string EventId { get; set; }
public virtual Event Event { get; set; }
public virtual List<EventAvailabilityResponse> EventAvailabilityResponses { get; set; }
}
Configuration Class:
internal class EventLocationConfiguration : EntityTypeConfiguration<EventLocation>
{
internal EventLocationConfiguration()
{
ToTable("EventLocations");
HasMany(e => e.EventAvailabilityResponses)
.WithMany(e => e.PreferredEventLocations)
.Map(m => m.ToTable("EventAvailabilityResponseEventLocations")
.MapLeftKey("EventLocationId").MapRightKey("EventAvailabilityResponseId"));
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (7 by maintainers)
Top Results From Across the Web
Audit.EntityFramework
AuditEntityCreator: An alternative to the mapper, as a function that creates the audit entity instance from the Event Entry and the Audit DbContext....
Read more >Audit Trail Implementation in ASP.NET Core with Entity ...
In this article, we will go through Audit Trail Implementation in ASP.NET Core (.NET 5) using Entity Framework Core. So what's this Audit...
Read more >Entity Framework with Audit Tables
This project describes how to use Entity Framework with update triggers and audit tables.
Read more >Entity Framework Core with Audit Tables
This project describes how to use Entity Framework Core with update triggers and audit tables.
Read more >Audit.NET Entity Framework to audit one same entry to two ...
I Have 2 Audit tables one is Audit_ProfileFan and second is Audit_StatusChanges The first table AuditProfileFan should audit every time update ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just pushed version 9.1.0 that includes the
Associations
property on theEntityFrameworkEvent
.Make sure to set the
IncludeIndependantAssociations
property to true on the Attribute or whatever method you use to configure the audit, since they are disabled by default.Feel free to re-open the issue if you are still having problems.
No it’s not on EF Core.
I was unable to find a solution for EF core. Looks like the core version does not expose the associasions as relation entries on the change tracker.
If you have any suggestion please let me know