private void ProcessElement(IReadOnlyAnnotatable metadata, string version)
        {
            if (version.StartsWith("1.", StringComparison.Ordinal) &&
                metadata is IMutableAnnotatable mutableMetadata)
            {
                foreach (var annotation in mutableMetadata.GetAnnotations().ToList())
                {
                    var colon = annotation.Name.IndexOf(':');
                    if (colon > 0)
                    {
                        var stripped = annotation.Name.Substring(colon);
                        if (_relationalNames.Contains(stripped))
                        {
                            mutableMetadata.RemoveAnnotation(annotation.Name);
                            var relationalName = "Relational" + stripped;
                            var duplicate      = mutableMetadata.FindAnnotation(relationalName);

                            if (duplicate == null)
                            {
                                mutableMetadata[relationalName] = annotation.Value;
                            }
                            else if (!Equals(duplicate.Value, annotation.Value))
                            {
                                _operationReporter.WriteWarning(
                                    DesignStrings.MultipleAnnotationConflict(stripped.Substring(1)));
                            }
                        }
                    }
                }
            }
        }
        public static string AnnotationsToDebugString([NotNull] this IReadOnlyAnnotatable annotatable, int indent = 0)
        {
            var annotations = annotatable.GetAnnotations().ToList();

            if (annotations.Count == 0)
            {
                return("");
            }

            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder.AppendLine().Append(indentString).Append("Annotations: ");
            foreach (var annotation in annotations)
            {
                builder
                .AppendLine()
                .Append(indentString)
                .Append("  ")
                .Append(annotation.Name)
                .Append(": ")
                .Append(annotation.Value);
            }

            return(builder.ToString());
        }
        /// <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>
        internal static IAnnotation GetAnnotation(IReadOnlyAnnotatable annotatable, string annotationName)
        {
            Check.NotEmpty(annotationName, nameof(annotationName));

            var annotation = annotatable.FindAnnotation(annotationName);
            if (annotation == null)
            {
                throw new InvalidOperationException(CoreStrings.AnnotationNotFound(annotationName, annotatable.ToString()));
            }

            return annotation;
        }
Exemple #4
0
        /// <summary>
        /// Finds a <see cref="PostgresRange"/> in the <see cref="IAnnotatable"/>, or returns null if not found.
        /// </summary>
        /// <param name="annotatable">The annotatable to search for the range.</param>
        /// <param name="schema">The range schema or null to use the model's default schema.</param>
        /// <param name="name">The range name.</param>
        /// <returns>
        /// The <see cref="PostgresRange"/> from the <see cref="IAnnotatable"/>.
        /// </returns>
        /// <exception cref="ArgumentException"><paramref name="schema"/></exception>
        /// <exception cref="ArgumentNullException"><paramref name="annotatable"/></exception>
        /// <exception cref="ArgumentNullException"><paramref name="name"/></exception>
        public static PostgresRange?FindPostgresRange(
            IReadOnlyAnnotatable annotatable,
            string?schema,
            string name)
        {
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NullButNotEmpty(schema, nameof(schema));
            Check.NotEmpty(name, nameof(name));

            var annotationName = BuildAnnotationName(schema, name);

            return(annotatable[annotationName] == null ? null : new PostgresRange(annotatable, annotationName));
        }
Exemple #5
0
        public static PostgresEnum FindPostgresEnum(
            [NotNull] IReadOnlyAnnotatable annotatable,
            [CanBeNull] string schema,
            [NotNull] string name)
        {
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NullButNotEmpty(schema, nameof(schema));
            Check.NotEmpty(name, nameof(name));

            var annotationName = BuildAnnotationName(schema, name);

            return(annotatable[annotationName] == null ? null : new PostgresEnum(annotatable, annotationName));
        }
        public static IAnnotation GetAnnotation([NotNull] this IReadOnlyAnnotatable annotatable, [NotNull] string annotationName)
        {
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotEmpty(annotationName, nameof(annotationName));

            var annotation = annotatable.FindAnnotation(annotationName);

            if (annotation == null)
            {
                throw new InvalidOperationException(CoreStrings.AnnotationNotFound(annotationName, annotatable.ToString()));
            }

            return(annotation);
        }
Exemple #7
0
 public CockroachDbInterleaveInParent([NotNull] IReadOnlyAnnotatable annotatable)
 => _annotatable = annotatable;
Exemple #8
0
 /// <summary>
 /// Creates a <see cref="PostgresRange"/>.
 /// </summary>
 /// <param name="annotatable">The annotatable to search for the annotation.</param>
 /// <param name="annotationName">The annotation name to search for in the annotatable.</param>
 /// <exception cref="ArgumentNullException"><paramref name="annotatable"/></exception>
 /// <exception cref="ArgumentNullException"><paramref name="annotationName"/></exception>
 internal PostgresRange(IReadOnlyAnnotatable annotatable, string annotationName)
 {
     _annotatable    = Check.NotNull(annotatable, nameof(annotatable));
     _annotationName = Check.NotNull(annotationName, nameof(annotationName));
 }
Exemple #9
0
 /// <summary>
 /// Gets the collection of <see cref="PostgresRange"/> stored in the <see cref="IAnnotatable"/>.
 /// </summary>
 /// <param name="annotatable">The annotatable to search for <see cref="PostgresRange"/> annotations.</param>
 /// <returns>
 /// The collection of <see cref="PostgresRange"/> stored in the <see cref="IAnnotatable"/>.
 /// </returns>
 /// <exception cref="ArgumentNullException"><paramref name="annotatable"/></exception>
 public static IEnumerable <PostgresRange> GetPostgresRanges(IReadOnlyAnnotatable annotatable)
 => Check.NotNull(annotatable, nameof(annotatable))
 .GetAnnotations()
 .Where(a => a.Name.StartsWith(NpgsqlAnnotationNames.RangePrefix, StringComparison.Ordinal))
 .Select(a => new PostgresRange(annotatable, a.Name));
Exemple #10
0
 /// <summary>
 /// Creates a <see cref="PostgresEnum"/>.
 /// </summary>
 /// <param name="annotatable">The annotatable to search for the annotation.</param>
 /// <param name="annotationName">The annotation name to search for in the annotatable.</param>
 /// <exception cref="ArgumentNullException"><paramref name="annotatable"/></exception>
 /// <exception cref="ArgumentNullException"><paramref name="annotationName"/></exception>
 internal PostgresEnum([NotNull] IReadOnlyAnnotatable annotatable, [NotNull] string annotationName)
 {
     _annotatable    = Check.NotNull(annotatable, nameof(annotatable));
     _annotationName = Check.NotNull(annotationName, nameof(annotationName));
 }
 public static IEnumerable <PostgresCollation> GetCollations([NotNull] IReadOnlyAnnotatable annotatable)
 => Check.NotNull(annotatable, nameof(annotatable))
 .GetAnnotations()
 .Where(a => a.Name.StartsWith(NpgsqlAnnotationNames.CollationDefinitionPrefix, StringComparison.Ordinal))
 .Select(a => new PostgresCollation(annotatable, a.Name));