public virtual void Generate(InternalEntityEntry entry, bool includePrimaryKey = true) { var entityEntry = new EntityEntry(entry); foreach (var property in entry.EntityType.GetValueGeneratingProperties()) { if (!entry.HasDefaultValue(property) || (!includePrimaryKey && property.IsPrimaryKey())) { continue; } var valueGenerator = GetValueGenerator(entry, property); var generatedValue = valueGenerator.Next(entityEntry); var temporary = valueGenerator.GeneratesTemporaryValues; Log(entry, property, generatedValue, temporary); SetGeneratedValue( entry, property, generatedValue, temporary); } }
public virtual async Task GenerateAsync( InternalEntityEntry entry, bool includePrimaryKey = true, CancellationToken cancellationToken = default) { var entityEntry = new EntityEntry(entry); foreach (var property in entry.EntityType.GetValueGeneratingProperties()) { if (!entry.HasDefaultValue(property) || (!includePrimaryKey && property.IsPrimaryKey())) { continue; } var valueGenerator = GetValueGenerator(entry, property); var generatedValue = await valueGenerator.NextAsync(entityEntry, cancellationToken) .ConfigureAwait(false); var temporary = valueGenerator.GeneratesTemporaryValues; Log(entry, property, generatedValue, temporary); SetGeneratedValue( entry, property, generatedValue, temporary); } }
private static IEnumerable <IProperty> FindGeneratingProperties(InternalEntityEntry entry) { foreach (var property in ((EntityType)entry.EntityType).GetProperties()) { if (property.RequiresValueGenerator() && entry.HasDefaultValue(property)) { yield return(property); } } }
private static IEnumerable <IProperty> FindPropagatingProperties(InternalEntityEntry entry) { foreach (var property in ((EntityType)entry.EntityType).GetProperties()) { if (property.IsForeignKey() && entry.HasDefaultValue(property)) { yield return(property); } } }
private static IEnumerable <IProperty> FindGeneratingProperties(InternalEntityEntry entry, bool includePKs = true) { foreach (var property in ((EntityType)entry.EntityType).GetProperties()) { if (property.RequiresValueGenerator() && entry.HasDefaultValue(property) && (includePKs || !property.IsPrimaryKey())) { yield return(property); } } }
public virtual InternalEntityEntry?Propagate(InternalEntityEntry entry) { InternalEntityEntry?chosenPrincipal = null; foreach (var property in entry.EntityType.GetForeignKeyProperties()) { if (!entry.HasDefaultValue(property)) { continue; } var principalEntry = _keyPropagator.PropagateValue(entry, property); if (chosenPrincipal == null) { chosenPrincipal = principalEntry; } } return(chosenPrincipal); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual InternalEntityEntry Propagate(InternalEntityEntry entry) { InternalEntityEntry chosenPrincipal = null; foreach (var property in FindCandidatePropagatingProperties(entry)) { if (!entry.HasDefaultValue(property)) { continue; } var principalEntry = _keyPropagator.PropagateValue(entry, property); if (chosenPrincipal == null) { chosenPrincipal = principalEntry; } } return(chosenPrincipal); }