public virtual void Generate(InternalEntityEntry entry) { foreach (var property in entry.EntityType.GetProperties()) { var isForeignKey = property.IsForeignKey(entry.EntityType); if ((property.RequiresValueGenerator || isForeignKey) && property.IsSentinelValue(entry[property])) { if (isForeignKey) { _keyPropagator.PropagateValue(entry, property); } else { var valueGenerator = _valueGeneratorSelector.Select(property, entry.EntityType); Debug.Assert(valueGenerator != null); var generatedValue = valueGenerator.NextSkippingSentinel(property); SetGeneratedValue(entry, property, generatedValue, valueGenerator.GeneratesTemporaryValues); } } } }
public virtual void Generate(InternalEntityEntry entry) { foreach (var property in entry.EntityType.GetProperties()) { var isForeignKey = property.IsForeignKey(entry.EntityType); if ((property.RequiresValueGenerator || isForeignKey) && property.ClrType.IsDefaultValue(entry[property])) { if (isForeignKey) { _keyPropagator.PropagateValue(entry, property); } else { var valueGenerator = _valueGeneratorSelector.Select(property, property.IsKey() ? property.DeclaringEntityType : entry.EntityType); Debug.Assert(valueGenerator != null); SetGeneratedValue(entry, property, valueGenerator.Next(), valueGenerator.GeneratesTemporaryValues); } } } }
private ValueGenerator TryGetValueGenerator(IProperty property) { var generationProperty = property.GetGenerationProperty(); return(generationProperty != null ? _valueGeneratorSelector.Select(generationProperty, generationProperty.DeclaringEntityType) : null); }
private ValueGenerator TryGetValueGenerator(IProperty property) { var generationProperty = property.GetGenerationProperty(); if (generationProperty != null) { return(_valueGeneratorSelector.Select(generationProperty, generationProperty.EntityType)); } return(null); }
/// <summary> /// Updates the database-generated properties for <paramref name="internalEntityEntry"/>. /// </summary> /// <param name="internalEntityEntry">The <see cref="IUpdateEntry"/> the <see cref="IUpdateEntry"/> representing the document being updated.</param> protected void UpdateDbGeneratedProperties(InternalEntityEntry internalEntityEntry) { var entityEntry = internalEntityEntry.ToEntityEntry(); foreach (IProperty property in _dbGeneratedProperties) { ValueGenerator valueGenerator = _valueGeneratorSelector.Select(property, internalEntityEntry.EntityType); object dbGeneratedValue = valueGenerator.Next(entityEntry); internalEntityEntry.SetProperty(property, dbGeneratedValue, true); property.GetSetter().SetClrValue(internalEntityEntry.Entity, dbGeneratedValue); } }
private ValueGenerator GetValueGenerator(InternalEntityEntry entry, IProperty property) => _valueGeneratorSelector.Select( property, property.IsKey() ? property.DeclaringEntityType : entry.EntityType);
private ValueGenerator GetValueGenerator(IProperty property) => _valueGeneratorSelector.Select(property, property.DeclaringEntityType);
private ValueGenerator?TryGetValueGenerator(IProperty?generationProperty) => generationProperty != null ? _valueGeneratorSelector.Select(generationProperty, generationProperty.DeclaringEntityType) : null;