Skip to content

Conversation

@albinma
Copy link
Contributor

@albinma albinma commented Oct 6, 2014

Entities that inherit from a base entity are not having their changed properties written to the audit log.
I believe the source of the problem lies with the way EntityType of an entity is being retrieved from the ObjectContext.

For example given the following Code First model:

public abstract class Vehicle
{
    public int VehicleID { get; set; }
    public int NumWheels { get; set; }
}

public class Car : Vehicle
{
    public int NumSeats { get; set; }
}

public class Truck : Vehicle
{
    public int MaxLoad { get; set; }
}

If you try to retrieve the EntityType of Car with the following line of code in EntityFramework.Audit.AuditEntryState line 23
EntityType = objectStateEntry.EntitySet.ElementType as EntityType;
The EntityType returned becomes Vehicle and not Car.

Later on in EntityFramework.Audit.AuditLogger line 227 when you compare the modified properties of Car using var properties = state.EntityType.Properties it would only give you a VehicleID and NumWheels off of the Vechicle.

This pull request modifies the EntityType retrieval strategy so that it will return the underlying EntityType of an entity that inherits from an abstract base entity which hopefully allows accurate modified properties comparison.

@albinma albinma changed the title Change AuditStateEntry's EntityState so that it returns the correct underlying EntityType Change AuditStateEntry's EntityType so that it returns the correct underlying EntityType Oct 6, 2014
pwelter34 added a commit that referenced this pull request Jul 9, 2015
Change AuditStateEntry's EntityType so that it returns the correct underlying EntityType
@pwelter34 pwelter34 merged commit b3910dc into zzzprojects:master Jul 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants