public override EntityState DetermineState(EntityEntry entry) { if (!entry.IsKeySet) { entry.GetService()[entry.Metadata.GetPrimaryKey().Properties.Single()] = 777; return(EntityState.Added); } return(base.DetermineState(entry)); }
public virtual IEnumerable <EntityEntry> TraverseGraph(object entity) { var entry = new EntityEntry(_context, _stateManager.GetOrCreateEntry(entity)); if (entry.State != EntityState.Detached) { yield break; } yield return(entry); if (entry.State != EntityState.Detached) { var internalEntry = entry.GetService(); var navigations = internalEntry.EntityType.GetNavigations(); foreach (var navigation in navigations) { var navigationValue = internalEntry[navigation]; if (navigationValue != null) { if (navigation.IsCollection()) { foreach (var relatedEntity in (IEnumerable)navigationValue) { foreach (var relatedEntry in TraverseGraph(relatedEntity)) { yield return(relatedEntry); } } } else { foreach (var relatedEntry in TraverseGraph(navigationValue)) { yield return(relatedEntry); } } } } } }
public virtual void TrackEntity(EntityEntry entry) => entry.GetService().SetEntityState(DetermineState(entry), acceptChanges: true);
public static Task ReloadAsync(this EntityEntry entityEntry, DbContext context) { return(entityEntry.GetService().ReloadAsync(context)); }
public static void Reload(this EntityEntry entityEntry, DbContext context) { entityEntry.GetService().Reload(context); }