In my many-to-one relationship I am trying to delete one of the child objects and keep an audit trail in my overridden SaveChanges.
The file.Entity.Product is not null when doing an EntityState.Modified or EntityState.Added but when doing a .Deleted EF seems to be aggressively removing the relationship from the entity even before base.Savechanges() is called.
Is there any way to retrieve when Product this file was associated with in my SaveChanges override after I have called .Remove on the File (child)?
var files = from e in ChangeTracker.Entries<SavedFile>()
where e.State != EntityState.Unchanged
select e;
if (file.State == EntityState.Deleted)
{
var text = "File Deleted: " + file.Entity.FriendlyFileName;
// file.Entity.Product is null
var updatedProduct = new Update { Product = file.Entity.Product, UpdateDateTime = DateTime.Now, UpdateText = text, User = HttpContext.Current.Request.LogonUserIdentity.Name };
Updates.Add(updatedProduct);
}
foreachloop overfilesassigning the value offile, right? - Shago