public virtual bool Annotation( [NotNull] string annotation, [CanBeNull] object value, ConfigurationSource configurationSource) { var existingValue = Metadata[annotation]; if (existingValue != null) { ConfigurationSource existingConfigurationSource; if (!_annotationSources.Value.TryGetValue(annotation, out existingConfigurationSource)) { existingConfigurationSource = ConfigurationSource.Explicit; } if ((value == null || existingValue != value) && !configurationSource.Overrides(existingConfigurationSource)) { return false; } configurationSource = configurationSource.Max(existingConfigurationSource); } if (value != null) { _annotationSources.Value[annotation] = configurationSource; Metadata[annotation] = value; } else { _annotationSources.Value.Remove(annotation); Metadata.RemoveAnnotation(new Annotation(annotation, "_")); } return true; }
private bool Annotation( string annotation, object value, ConfigurationSource configurationSource, bool canOverrideSameSource) { var existingValue = Metadata[annotation]; if (existingValue != null) { ConfigurationSource existingConfigurationSource; if (!_annotationSources.Value.TryGetValue(annotation, out existingConfigurationSource)) { existingConfigurationSource = ConfigurationSource.Explicit; } if ((value == null || !existingValue.Equals(value)) && (!configurationSource.Overrides(existingConfigurationSource) || configurationSource == existingConfigurationSource && !canOverrideSameSource)) { return false; } configurationSource = configurationSource.Max(existingConfigurationSource); } if (value != null) { _annotationSources.Value[annotation] = configurationSource; Metadata[annotation] = value; } else { _annotationSources.Value.Remove(annotation); Metadata.RemoveAnnotation(new Annotation(annotation, "_")); } return true; }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual bool ReadOnlyAfterSave(bool isReadOnlyAfterSave, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetIsReadOnlyAfterSaveConfigurationSource()) || (Metadata.IsReadOnlyAfterSave == isReadOnlyAfterSave)) { Metadata.SetIsReadOnlyAfterSave(isReadOnlyAfterSave, configurationSource); return(true); } return(false); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual bool IsConcurrencyToken(bool concurrencyToken, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetIsConcurrencyTokenConfigurationSource()) || (Metadata.IsConcurrencyToken == concurrencyToken)) { Metadata.SetIsConcurrencyToken(concurrencyToken, configurationSource); return(true); } return(false); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual bool IsUnique(bool isUnique, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetIsUniqueConfigurationSource()) || (Metadata.IsUnique == isUnique)) { Metadata.SetIsUnique(isUnique, configurationSource); return(true); } return(false); }
/// <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 IConventionSequenceBuilder?HasType(Type?type, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetTypeConfigurationSource()) || Metadata.Type == type) { Metadata.SetType(type, configurationSource); return(this); } return(null); }
/// <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 InternalServicePropertyBuilder HasField([CanBeNull] FieldInfo fieldInfo, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetFieldInfoConfigurationSource()) || Equals(Metadata.FieldInfo, fieldInfo)) { Metadata.SetField(fieldInfo, configurationSource); return(this); } return(null); }
public virtual bool HasClrType([NotNull] Type propertyType, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetClrTypeConfigurationSource()) || (Metadata.ClrType == propertyType)) { Metadata.HasClrType(propertyType, configurationSource); return(true); } return(false); }
public virtual bool IsShadow(bool isShadowProperty, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetIsShadowPropertyConfigurationSource()) || (Metadata.IsShadowProperty == isShadowProperty)) { Metadata.SetIsShadowProperty(isShadowProperty, configurationSource); return(true); } return(false); }
/// <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 IConventionSequenceBuilder HasType([CanBeNull] Type type, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetClrTypeConfigurationSource()) || Metadata.ClrType == type) { Metadata.SetClrType(type, configurationSource); return(this); } return(null); }
public virtual bool RequiresValueGenerator(bool generateValue, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetRequiresValueGeneratorConfigurationSource()) || (Metadata.RequiresValueGenerator == generateValue)) { Metadata.SetRequiresValueGenerator(generateValue, configurationSource); return(true); } return(false); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual bool AfterSave(PropertySaveBehavior?behavior, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetAfterSaveBehaviorConfigurationSource()) || Metadata.AfterSaveBehavior == behavior) { Metadata.SetAfterSaveBehavior(behavior, configurationSource); return(true); } return(false); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual bool ValueGenerated(ValueGenerated?valueGenerated, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetValueGeneratedConfigurationSource()) || Metadata.ValueGenerated == valueGenerated) { Metadata.SetValueGenerated(valueGenerated, configurationSource); return(true); } return(false); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual bool IsStoreGeneratedAlways(bool isStoreGeneratedAlways, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetIsStoreGeneratedAlwaysConfigurationSource()) || (Metadata.IsStoreGeneratedAlways == isStoreGeneratedAlways)) { Metadata.SetIsStoreGeneratedAlways(isStoreGeneratedAlways, configurationSource); return(true); } return(false); }
/// <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 InternalServicePropertyBuilder SetParameterBinding( [NotNull] ServiceParameterBinding parameterBinding, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetParameterBindingConfigurationSource()) || (Metadata.ParameterBinding == parameterBinding)) { Metadata.SetParameterBinding(parameterBinding, configurationSource); return(this); } return(null); }
/// <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 InternalPropertyBuilder HasField([CanBeNull] string fieldName, ConfigurationSource configurationSource) { if (Metadata.FieldInfo?.GetSimpleMemberName() == fieldName || configurationSource.Overrides(Metadata.GetFieldInfoConfigurationSource())) { Metadata.SetField(fieldName, configurationSource); return(this); } return(null); }
/// <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 InternalPropertyBuilder AfterSave(PropertySaveBehavior?behavior, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetAfterSaveBehaviorConfigurationSource()) || Metadata.GetAfterSaveBehavior() == behavior) { Metadata.SetAfterSaveBehavior(behavior, configurationSource); return(this); } return(null); }
/// <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 InternalPropertyBuilder HasConversion([CanBeNull] ValueConverter converter, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetValueConverterConfigurationSource()) || Metadata.GetValueConverter() == converter) { Metadata.SetValueConverter(converter, configurationSource); return(this); } return(null); }
/// <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 bool SetParameterBinding( [NotNull] ServiceParameterBinding parameterBinding, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetParameterBindingConfigurationSource()) || (Metadata.ParameterBinding == parameterBinding)) { Metadata.SetParameterBinding(parameterBinding, configurationSource); return(true); } return(false); }
public virtual ConfigurationSource?Remove([NotNull] TKey key, ConfigurationSource configurationSource, bool canOverrideSameSource = true) { Check.NotNull(key, nameof(key)); Tuple <TValue, ConfigurationSource> tuple; if (_values.TryGetValue(key, out tuple)) { if (configurationSource.Overrides(tuple.Item2) && (tuple.Item2 != configurationSource || canOverrideSameSource)) { _values.Remove(key); return(tuple.Item2); } return(null); } return(configurationSource.Overrides(DefaultConfigurationSource) && (DefaultConfigurationSource != configurationSource || canOverrideSameSource) ? DefaultConfigurationSource : (ConfigurationSource?)null); }
private static bool CanSetAnnotationValue( ConventionAnnotation annotation, object value, ConfigurationSource configurationSource, bool canOverrideSameSource) { if (Equals(annotation.Value, value)) { return true; } var existingConfigurationSource = annotation.GetConfigurationSource(); return configurationSource.Overrides(existingConfigurationSource) && (configurationSource != existingConfigurationSource || canOverrideSameSource); }
private bool CanRemove(ForeignKey foreignKey, ConfigurationSource configurationSource, bool canOverrideSameSource) { if (foreignKey.EntityType != Metadata) { return(ModelBuilder.Entity(foreignKey.EntityType.Name, ConfigurationSource.Convention) .CanRemove(foreignKey, configurationSource, canOverrideSameSource)); } var currentConfigurationSource = _relationshipBuilders.Value.GetConfigurationSource(foreignKey); return(configurationSource.Overrides(currentConfigurationSource) && (canOverrideSameSource || configurationSource != currentConfigurationSource)); }
private bool RemoveEntityType(EntityType entityType, ConfigurationSource configurationSource) { var entityTypeConfigurationSource = entityType.GetConfigurationSource(); if (!configurationSource.Overrides(entityTypeConfigurationSource)) { return(false); } // Set base type as null to remove the entityType from directly derived types of the base type var baseType = entityType.BaseType; entityType.Builder.HasBaseType((EntityType)null, configurationSource); var entityTypeBuilder = entityType.Builder; foreach (var foreignKey in entityType.GetDeclaredForeignKeys().ToList()) { var removed = entityTypeBuilder.RemoveForeignKey(foreignKey, configurationSource); Debug.Assert(removed.HasValue); } foreach (var foreignKey in entityType.GetDeclaredReferencingForeignKeys().ToList()) { var removed = foreignKey.DeclaringEntityType.Builder.RemoveForeignKey(foreignKey, configurationSource); Debug.Assert(removed.HasValue); } foreach (var directlyDerivedType in entityType.GetDirectlyDerivedTypes().ToList()) { var derivedEntityTypeBuilder = directlyDerivedType.Builder .HasBaseType(baseType, configurationSource); Debug.Assert(derivedEntityTypeBuilder != null); } foreach (var definedDelegatedTypes in Metadata.GetEntityTypes().Where(e => e.DefiningEntityType == entityType).ToList()) { RemoveDelegatedIdentityEntityType(definedDelegatedTypes, configurationSource); } if (entityType.HasDelegatedIdentity()) { Metadata.RemoveDelegatedIdentityEntityType(entityType); } else { Metadata.RemoveEntityType(entityType.Name); } return(true); }
public virtual bool Ignore([NotNull] string propertyName, ConfigurationSource configurationSource) { Check.NotEmpty(propertyName, "propertyName"); ConfigurationSource ignoredConfigurationSource; if (_ignoredProperties.Value.TryGetValue(propertyName, out ignoredConfigurationSource)) { if (!configurationSource.Overrides(ignoredConfigurationSource) || configurationSource == ignoredConfigurationSource) { return(true); } } var property = Metadata.TryGetProperty(propertyName); if (property != null) { if (!RemoveProperty(property, configurationSource)) { if (configurationSource == ConfigurationSource.Explicit) { throw new InvalidOperationException(Strings.PropertyAddedExplicitly(property.Name, Metadata.Name)); } return(false); } } var navigation = Metadata.TryGetNavigation(propertyName); if (navigation != null) { if (!Navigation(null, navigation.ForeignKey, navigation.PointsToPrincipal, configurationSource, canOverrideSameSource: false)) { if (configurationSource == ConfigurationSource.Explicit) { throw new InvalidOperationException(Strings.NavigationAddedExplicitly(navigation.Name, Metadata.Name)); } return(false); } RemoveForeignKeyIfUnused(navigation.ForeignKey, configurationSource); } _ignoredProperties.Value[propertyName] = configurationSource; return(true); }
public static bool CanSet(this ConfigurationSource newConfigurationSource, ConfigurationSource?oldConfigurationSource, bool isValueSet) { if (isValueSet) { var existingConfigurationSource = oldConfigurationSource ?? ConfigurationSource.Explicit; if (!newConfigurationSource.Overrides(existingConfigurationSource)) { return(false); } } return(true); }
private bool Owned( TypeIdentity type, ConfigurationSource configurationSource) { if (IsIgnored(type, configurationSource)) { return(false); } var clrType = type.Type; var entityType = clrType == null ? Metadata.FindEntityType(type.Name) : Metadata.FindEntityType(clrType); if (entityType != null && !entityType.GetForeignKeys().Any(fk => fk.IsOwnership)) { if (!configurationSource.Overrides(entityType.GetConfigurationSource())) { return(false); } if (entityType.GetConfigurationSource() == ConfigurationSource.Explicit) { throw new InvalidOperationException(CoreStrings.ClashingNonOwnedEntityType(entityType.DisplayName())); } var potentialOwnerships = entityType.GetForeignKeys().Where(fk => fk.PrincipalToDependent != null).ToList(); foreach (var foreignKey in potentialOwnerships) { foreignKey.PrincipalEntityType.FindNavigation(foreignKey.PrincipalToDependent.Name).ForeignKey.Builder .IsOwnership(true, configurationSource); } } if (clrType == null) { Metadata.Unignore(type.Name); Metadata.MarkAsOwnedType(type.Name); } else { Metadata.Unignore(clrType); Metadata.MarkAsOwnedType(clrType); } return(true); }
private static bool CanSetAnnotationValue( ConventionalAnnotation annotation, object value, ConfigurationSource configurationSource, bool canOverrideSameSource) { if (Equals(annotation.Value, value)) { return(true); } var existingConfigurationSource = annotation.GetConfigurationSource(); return(!configurationSource.Overrides(existingConfigurationSource) || ((configurationSource == existingConfigurationSource) && !canOverrideSameSource) ? false : true); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual bool HasFieldInfo([CanBeNull] FieldInfo fieldInfo, ConfigurationSource configurationSource) { if ((configurationSource.Overrides(Metadata.GetFieldInfoConfigurationSource()) && (fieldInfo == null || PropertyBase.IsCompatible( fieldInfo, Metadata.ClrType, Metadata.DeclaringType.ClrType, Metadata.Name, shouldThrow: configurationSource == ConfigurationSource.Explicit))) || Equals(Metadata.FieldInfo, fieldInfo)) { Metadata.SetFieldInfo(fieldInfo, configurationSource); return(true); } return(false); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual bool IsRequired(bool?isRequired, ConfigurationSource configurationSource) { if (isRequired.HasValue) { return(IsRequired(isRequired.Value, configurationSource)); } if (configurationSource.Overrides(Metadata.GetIsNullableConfigurationSource())) { Metadata.SetIsNullable(null, configurationSource); return(true); } return(false); }
/// <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 InternalSkipNavigationBuilder HasForeignKey([CanBeNull] ForeignKey foreignKey, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetForeignKeyConfigurationSource()) || Equals(Metadata.ForeignKey, foreignKey)) { if (foreignKey != null) { foreignKey.UpdateConfigurationSource(configurationSource); } Metadata.SetForeignKey(foreignKey, configurationSource); return(this); } return(null); }
private bool Owned(TypeIdentity type, ConfigurationSource configurationSource) { if (IsIgnored(type, configurationSource)) { return(false); } var clrType = type.Type; var entityType = clrType == null ? Metadata.FindEntityType(type.Name) : Metadata.FindEntityType(clrType); if (entityType != null && !entityType.GetForeignKeys().Any(fk => fk.IsOwnership)) { if (!configurationSource.Overrides(entityType.GetConfigurationSource())) { return(false); } if (entityType.GetConfigurationSource() == ConfigurationSource.Explicit) { throw new InvalidOperationException(CoreStrings.ClashingNonOwnedEntityType(entityType.DisplayName())); } var ownership = entityType.GetForeignKeys().FirstOrDefault(fk => fk.PrincipalToDependent != null && !fk.PrincipalEntityType.IsInOwnershipPath(entityType) && !fk.PrincipalEntityType.IsInDefinitionPath(clrType)); ownership?.Builder.IsOwnership(true, configurationSource); } if (clrType == null) { Metadata.Unignore(type.Name); Metadata.MarkAsOwnedType(type.Name); } else { Metadata.Unignore(clrType); Metadata.MarkAsOwnedType(clrType); } return(true); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual bool RemoveEntityType([NotNull] EntityType entityType, ConfigurationSource configurationSource) { var entityTypeConfigurationSource = entityType.GetConfigurationSource(); if (!configurationSource.Overrides(entityTypeConfigurationSource)) { return(false); } // Set base type as null to remove the entityType from directly derived types of the base type var baseType = entityType.BaseType; entityType.Builder.HasBaseType((EntityType)null, configurationSource); var entityTypeBuilder = entityType.Builder; foreach (var foreignKey in entityType.GetDeclaredForeignKeys().ToList()) { var removed = entityTypeBuilder.RemoveForeignKey(foreignKey, configurationSource); Debug.Assert(removed.HasValue); } foreach (var foreignKey in entityType.GetDeclaredReferencingForeignKeys().ToList()) { var removed = foreignKey.DeclaringEntityType.Builder.RemoveForeignKey(foreignKey, configurationSource); Debug.Assert(removed.HasValue); } foreach (var directlyDerivedType in entityType.GetDirectlyDerivedTypes().ToList()) { var derivedEntityTypeBuilder = directlyDerivedType.Builder .HasBaseType(baseType, configurationSource); Debug.Assert(derivedEntityTypeBuilder != null); } using (Metadata.ConventionDispatcher.StartBatch()) { foreach (var definedType in Metadata.GetEntityTypes().Where(e => e.DefiningEntityType == entityType).ToList()) { RemoveEntityType(definedType, configurationSource); } Metadata.RemoveEntityType(entityType); } return(true); }
private bool HasAnnotation( string name, object value, ConfigurationSource configurationSource, bool canOverrideSameSource) { var existingAnnotation = Metadata.FindAnnotation(name); if (existingAnnotation != null) { if (existingAnnotation.Value.Equals(value)) { existingAnnotation.UpdateConfigurationSource(configurationSource); return true; } var existingConfigurationSource = existingAnnotation.GetConfigurationSource(); if (!configurationSource.Overrides(existingConfigurationSource) || (configurationSource == existingConfigurationSource && !canOverrideSameSource)) { return false; } if (value == null) { var removed = Metadata.RemoveAnnotation(name); Debug.Assert(removed == existingAnnotation); } else { Metadata.SetAnnotation(name, value, configurationSource); } return true; } if (value != null) { Metadata.AddAnnotation(name, value, configurationSource); } return true; }
private bool CanSetAnnotationValue( ConventionalAnnotation annotation, object value, ConfigurationSource configurationSource, bool canOverrideSameSource) { if (annotation.Value.Equals(value)) { return true; } var existingConfigurationSource = annotation.GetConfigurationSource(); if (!configurationSource.Overrides(existingConfigurationSource) || ((configurationSource == existingConfigurationSource) && !canOverrideSameSource)) { return false; } return true; }