So we do it in our code. Lazy loading and proxy creation is available.
Please note that when creating a proxy server, EF will know which property has changed, you do not need to go to the database. The only place EF does not know is if any other context changed the row (concurrency error) to avoid using the RowVersion column / property
In the constructor:
public DataContext() : base() { this.Configuration.ProxyCreationEnabled = true; this.Configuration.LazyLoadingEnabled = true; var objectContext = ((IObjectContextAdapter)this).ObjectContext; objectContext.SavingChanges += new EventHandler(objectContext_SavingChanges); } private void objectContext_SavingChanges(object sender, EventArgs e) { var objectContext = (ObjectContext)sender; var modifiedEntities = objectContext.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Added | System.Data.EntityState.Modified); foreach (var entry in modifiedEntities) { var entity = entry.Entity as BusinessBase; if (entity != null) { entity.ModDateTime = DateTime.Now; entity.ModUser = Thread.CurrentPrincipal.Identity.Name; } } }
source share