public static IConventionAnnotation?SetOrRemoveAnnotation( [NotNull] this IConventionAnnotatable annotatable, [NotNull] string name, [CanBeNull] object?value, bool fromDataAnnotation = false) => ((ConventionAnnotatable)annotatable).SetOrRemoveAnnotation( name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);
public static void AddAnnotations( [NotNull] this IConventionAnnotatable annotatable, [NotNull] IEnumerable <IConventionAnnotation> annotations, bool fromDataAnnotation = false) { foreach (var annotation in annotations) { annotatable.AddAnnotation(annotation.Name, annotation.Value, fromDataAnnotation); } }
/// <summary> /// Sets the annotation stored under the given name. Overwrites the existing annotation if an /// annotation with the specified name already exists. Removes the existing annotation if <c>null</c> is supplied. /// </summary> /// <param name="annotatable"> The object to set the annotation for. </param> /// <param name="name"> The name of the annotation to be added. </param> /// <param name="value"> The value to be stored in the annotation. </param> /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param> public static void SetOrRemoveAnnotation( [NotNull] this IConventionAnnotatable annotatable, [NotNull] string name, [CanBeNull] object value, bool fromDataAnnotation = false) { if (value == null) { annotatable.RemoveAnnotation(name); } else { annotatable.SetAnnotation(name, value, fromDataAnnotation); } }
/// <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 void MergeAnnotationsFrom( [NotNull] IConventionAnnotatable annotatable, ConfigurationSource minimalConfigurationSource) { foreach (var annotation in annotatable.GetAnnotations()) { var configurationSource = annotation.GetConfigurationSource(); if (configurationSource.Overrides(minimalConfigurationSource)) { HasAnnotation( annotation.Name, annotation.Value, configurationSource, canOverrideSameSource: false); } } }
/// <summary> /// Gets or adds a <see cref="PostgresExtension"/> from or to the <see cref="IMutableAnnotatable"/>. /// </summary> /// <param name="annotatable">The annotatable from which to get or add the extension.</param> /// <param name="schema">The extension schema or null to use the model's default schema.</param> /// <param name="name">The extension name.</param> /// <param name="version">The extension version.</param> /// <returns> /// The <see cref="PostgresExtension"/> from the <see cref="IMutableAnnotatable"/>. /// </returns> /// <exception cref="ArgumentException"><paramref name="schema"/></exception> /// <exception cref="ArgumentNullException"><paramref name="annotatable"/></exception> /// <exception cref="ArgumentNullException"><paramref name="name"/></exception> public static PostgresExtension GetOrAddPostgresExtension( IConventionAnnotatable annotatable, string?schema, string name, string?version) { Check.NotNull(annotatable, nameof(annotatable)); Check.NullButNotEmpty(schema, nameof(schema)); Check.NotNull(name, nameof(name)); if (FindPostgresExtension(annotatable, schema, name) is { } postgresExtension) { return(postgresExtension); } var annotationName = BuildAnnotationName(schema, name); return(new PostgresExtension(annotatable, annotationName) { Version = version }); }
public static IConventionAnnotation GetAnnotation( [NotNull] this IConventionAnnotatable annotatable, [NotNull] string annotationName) => (IConventionAnnotation)((IReadOnlyAnnotatable)annotatable).GetAnnotation(annotationName);
/// <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 void MergeAnnotationsFrom([NotNull] IConventionAnnotatable annotatable) => MergeAnnotationsFrom(annotatable, ConfigurationSource.Explicit);