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

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

            VerifyError(MySqlStrings.IncludePropertyNotFound(nameof(Dog), "Tag"), modelBuilder.Model);
        }
Пример #2
0
        public void Detects_missing_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.Type), "Tag");
#pragma warning restore 618
            }
            else
            {
                modelBuilder.Entity <Dog>().HasIndex(nameof(Dog.Name)).IncludeProperties(nameof(Dog.Type), "Tag");
            }

            VerifyError(MySqlStrings.IncludePropertyNotFound(nameof(Dog), "Tag"), 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));
                    }
                }
            }
        }