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.

How to audit join tables with Audit.EntityFramework?

See original GitHub issue

Given 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:closed
  • Created 6 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
thepirat000commented, Nov 21, 2017

Just pushed version 9.1.0 that includes the Associations property on the EntityFrameworkEvent.

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.

0reactions
thepirat000commented, Feb 14, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

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