Some of the entities in my application have 4 audit properties on them:
public virtual DateTime WhenAdded { get; set; }
public virtual DateTime? WhenUpdated { get; set; }
public virtual User AddedBy { get; set; }
public virtual User UpdatedBy { get; set; }
I am using a code first approach and have the following extension method to map the user properties:
public static void MapAuditFields<T>(this EntityTypeConfiguration<T> configuration) where T : class, IAuditable
{
configuration.HasOptional<User>(e => e.AddedBy)
.WithOptionalDependent()
.Map(a => a.MapKey("AddedByUserId"));
configuration.HasOptional<User>(e => e.UpdatedBy)
.WithOptionalDependent()
.Map(a => a.MapKey("UpdatedByUserId"));
}
This is working fine in most cases, but not on the User class, which of course has a recursive relationship with itself. I have seen various posts on the internet suggesting that entity framework has a bug when you try to customise join table column names in this scenario, for example:
Self-referencing many-to-many recursive relationship code first Entity Framework
and
The error I am getting is "Sequence contains more than one matching element".
Does anyone know if this has been fixed in entity framework 6?
Many thanks.