Пример #1
0
        /// <inheritdoc />
        public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext <IConventionModelBuilder> context)
        {
            foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
            {
                var duplicateMap = GetDuplicateServiceProperties(entityType);
                if (duplicateMap == null)
                {
                    continue;
                }

                foreach (var duplicateServiceProperties in duplicateMap.Values)
                {
                    foreach (var duplicateServiceProperty in duplicateServiceProperties)
                    {
                        if (entityType.FindProperty(duplicateServiceProperty.GetSimpleMemberName()) == null &&
                            entityType.FindNavigation(duplicateServiceProperty.GetSimpleMemberName()) == null)
                        {
                            throw new InvalidOperationException(
                                      CoreStrings.AmbiguousServiceProperty(
                                          duplicateServiceProperty.Name,
                                          duplicateServiceProperty.GetMemberType().ShortDisplayName(),
                                          entityType.DisplayName()));
                        }
                    }
                }

                SetDuplicateServiceProperties(entityType.Builder, null);
            }
        }
        /// <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 InternalModelBuilder Apply(InternalModelBuilder modelBuilder)
        {
            foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
            {
                var duplicateMap = GetDuplicateServiceProperties(entityType);
                if (duplicateMap == null)
                {
                    continue;
                }

                foreach (var duplicateServiceProperties in duplicateMap.Values)
                {
                    foreach (var duplicateServiceProperty in duplicateServiceProperties)
                    {
                        if (entityType.FindProperty(duplicateServiceProperty.Name) == null &&
                            entityType.FindNavigation(duplicateServiceProperty.Name) == null)
                        {
                            throw new InvalidOperationException(CoreStrings.AmbiguousServiceProperty(
                                                                    duplicateServiceProperty.Name,
                                                                    duplicateServiceProperty.GetMemberType().ShortDisplayName(),
                                                                    entityType.DisplayName()));
                        }
                    }
                }

                SetDuplicateServiceProperties(entityType.Builder, null);
            }

            return(modelBuilder);
        }
Пример #3
0
        public void Does_not_find_duplicate_service_properties()
        {
            var entityType = RunConvention <BlogDuplicateService>();

            Assert.Empty(entityType.GetServiceProperties());

            Assert.Equal(
                CoreStrings.AmbiguousServiceProperty(
                    nameof(BlogDuplicateService.ContextTwo), nameof(DbContext), nameof(BlogDuplicateService)),
                Assert.Throws <InvalidOperationException>(
                    () => Validate(entityType)).Message);
        }
Пример #4
0
        public void Does_not_find_duplicate_service_properties()
        {
            var convention = TestServiceFactory.Instance.Create <ServicePropertyDiscoveryConvention>();
            var entityType = new Model().AddEntityType(typeof(BlogDuplicateService));

            convention.Apply(entityType.Builder);

            Assert.Empty(entityType.GetServiceProperties());

            Assert.Equal(
                CoreStrings.AmbiguousServiceProperty(nameof(BlogDuplicateService.ContextTwo), nameof(DbContext), nameof(BlogDuplicateService)),
                Assert.Throws <InvalidOperationException>(() =>
                                                          TestServiceFactory.Instance.Create <ServicePropertyDiscoveryConvention>().Apply(entityType.Model.Builder)).Message);
        }