public void Throws_for_indexed_include_properties()
        {
            var modelBuilder = InMemoryTestHelpers.Instance.CreateConventionBuilder();

            modelBuilder.Entity <Dog>().Property(c => c.Type);
            modelBuilder.Entity <Dog>().HasIndex(nameof(Dog.Name)).ForMySqlInclude(nameof(Dog.Name));

            VerifyError(MySqlStrings.IncludePropertyInIndex(nameof(Dog), nameof(Dog.Name)), modelBuilder.Model);
        }
예제 #2
0
        public void Detects_indexed_include_properties(bool obsolete)
        {
            var modelBuilder = CreateConventionalModelBuilder();

            modelBuilder.Entity <Dog>().Property(c => c.Type);
            if (obsolete)
            {
#pragma warning disable 618
                modelBuilder.Entity <Dog>().HasIndex(nameof(Dog.Name)).ForMySqlInclude(nameof(Dog.Name));
#pragma warning restore 618
            }
            else
            {
                modelBuilder.Entity <Dog>().HasIndex(nameof(Dog.Name)).IncludeProperties(nameof(Dog.Name));
            }

            VerifyError(MySqlStrings.IncludePropertyInIndex(nameof(Dog), nameof(Dog.Name)), modelBuilder.Model);
        }
예제 #3
0
        /// <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>
        protected virtual void ValidateIndexIncludeProperties([NotNull] IModel model)
        {
            foreach (var index in model.GetEntityTypes().SelectMany(t => t.GetDeclaredIndexes()))
            {
                var includeProperties = index.MySql().IncludeProperties;
                if (includeProperties?.Count > 0)
                {
                    var notFound = includeProperties
                                   .Where(i => index.DeclaringEntityType.FindProperty(i) == null)
                                   .FirstOrDefault();

                    if (notFound != null)
                    {
                        throw new InvalidOperationException(
                                  MySqlStrings.IncludePropertyNotFound(index.DeclaringEntityType.DisplayName(), notFound));
                    }

                    var duplicate = includeProperties
                                    .GroupBy(i => i)
                                    .Where(g => g.Count() > 1)
                                    .Select(y => y.Key)
                                    .FirstOrDefault();

                    if (duplicate != null)
                    {
                        throw new InvalidOperationException(
                                  MySqlStrings.IncludePropertyDuplicated(index.DeclaringEntityType.DisplayName(), duplicate));
                    }

                    var inIndex = includeProperties
                                  .Where(i => index.Properties.Any(p => i == p.Name))
                                  .FirstOrDefault();

                    if (inIndex != null)
                    {
                        throw new InvalidOperationException(
                                  MySqlStrings.IncludePropertyInIndex(index.DeclaringEntityType.DisplayName(), inIndex));
                    }
                }
            }
        }