private EntityEntry AddEntityEntry(EFEntityInfo entityInfo) { var entry = GetEntityEntry(entityInfo.Entity); if (entry.State == Microsoft.EntityFrameworkCore.EntityState.Detached) { return(DbContext.Add(entityInfo.Entity)); } else { return(entry); } }
private EntityEntry HandleModified(EFEntityInfo entityInfo) { var entry = AddEntityEntry(entityInfo); // EntityState will be changed to modified during the update from the OriginalValuesMap // Do NOT change this to EntityState.Modified because this will cause the entire record to update. entry.State = Microsoft.EntityFrameworkCore.EntityState.Unchanged; // updating the original values is necessary under certain conditions when we change a foreign key field // because the before value is used to determine ordering. UpdateOriginalValues(entry, entityInfo); // SetModified(entry, entityInfo.ForceUpdate); MarkEntryAndOwnedChildren(entry, Microsoft.EntityFrameworkCore.EntityState.Modified); return(entry); }
private EntityEntry HandleAdded(EFEntityInfo entityInfo) { var entry = AddEntityEntry(entityInfo); if (entityInfo.AutoGeneratedKey != null) { var propName = entityInfo.AutoGeneratedKey.PropertyName; entityInfo.AutoGeneratedKey.TempValue = GetEntryPropertyValue(entry, propName); if (entityInfo.AutoGeneratedKey.AutoGeneratedKeyType == AutoGeneratedKeyType.Identity) { // HACK: because EF Core will not allow inserts to an Identity column where a value exists on incoming entity. entry.Property(propName).IsTemporary = true; } } MarkEntryAndOwnedChildren(entry, Microsoft.EntityFrameworkCore.EntityState.Added); return(entry); }
private EntityEntry GetEntityEntry(EFEntityInfo entityInfo) { return(GetEntityEntry(entityInfo.Entity)); }
private EntityEntry AttachEntityEntry(EFEntityInfo entityInfo) { return(DbContext.Attach(entityInfo.Entity)); }
private EntityEntry GetOrAddEntityEntry(EFEntityInfo entityInfo) { return(AddEntityEntry(entityInfo)); }