Example #1
0
        public virtual EntityType AddEntityType(
            [NotNull] string name, ConfigurationSource configurationSource = ConfigurationSource.Explicit)
        {
            Check.NotEmpty(name, nameof(name));

            var entityType = AddEntityTypeWithoutConventions(name, configurationSource);

            return(ConventionDispatcher.OnEntityTypeAdded(entityType.Builder)?.Metadata);
        }
Example #2
0
        public virtual EntityType AddEntityType(
            [NotNull] Type type, ConfigurationSource configurationSource = ConfigurationSource.Explicit)
        {
            Check.NotNull(type, nameof(type));

            var entityType = AddEntityTypeWithoutConventions(type.DisplayName(), configurationSource);

            entityType.ClrType = type;

            return(ConventionDispatcher.OnEntityTypeAdded(entityType.Builder)?.Metadata);
        }
Example #3
0
        private EntityType AddEntityType(EntityType entityType)
        {
            var previousLength = _entityTypes.Count;

            _entityTypes[entityType.Name] = entityType;
            if (previousLength == _entityTypes.Count)
            {
                throw new InvalidOperationException(CoreStrings.DuplicateEntityType(entityType.Name));
            }

            return(ConventionDispatcher.OnEntityTypeAdded(entityType.Builder)?.Metadata);
        }
Example #4
0
        private EntityType AddEntityType(EntityType entityType)
        {
            var entityTypeName = entityType.Name;

            if (entityType.HasDefiningNavigation())
            {
                if (_entityTypes.ContainsKey(entityTypeName))
                {
                    throw new InvalidOperationException(CoreStrings.ClashingNonWeakEntityType(entityType.DisplayName()));
                }

                if (!_entityTypesWithDefiningNavigation.TryGetValue(entityTypeName, out var entityTypesWithSameType))
                {
                    entityTypesWithSameType = new SortedSet <EntityType>(EntityTypePathComparer.Instance);
                    _entityTypesWithDefiningNavigation[entityTypeName] = entityTypesWithSameType;
                }

                var added = entityTypesWithSameType.Add(entityType);
                Debug.Assert(added);
            }
            else
            {
                if (_entityTypesWithDefiningNavigation.ContainsKey(entityTypeName))
                {
                    throw new InvalidOperationException(CoreStrings.ClashingWeakEntityType(entityType.DisplayName()));
                }

                if (_entityTypes.TryGetValue(entityTypeName, out var clashingEntityType))
                {
                    if (clashingEntityType.IsQueryType)
                    {
                        if (entityType.IsQueryType)
                        {
                            throw new InvalidOperationException(CoreStrings.DuplicateQueryType(entityType.DisplayName()));
                        }
                        throw new InvalidOperationException(CoreStrings.CannotAccessQueryAsEntity(entityType.DisplayName()));
                    }

                    if (entityType.IsQueryType)
                    {
                        throw new InvalidOperationException(CoreStrings.CannotAccessEntityAsQuery(entityType.DisplayName()));
                    }
                    throw new InvalidOperationException(CoreStrings.DuplicateEntityType(entityType.DisplayName()));
                }

                _entityTypes.Add(entityTypeName, entityType);
            }

            return(ConventionDispatcher.OnEntityTypeAdded(entityType.Builder)?.Metadata);
        }
Example #5
0
        private EntityType AddEntityType(EntityType entityType)
        {
            var entityTypeName = entityType.Name;

            if (_delegatedIdentityEntityTypes.ContainsKey(entityTypeName))
            {
                throw new InvalidOperationException(CoreStrings.ClashingDelegatedIdentityEntityType(entityType.DisplayName()));
            }

            var previousLength = _entityTypes.Count;

            _entityTypes[entityTypeName] = entityType;
            if (previousLength == _entityTypes.Count)
            {
                throw new InvalidOperationException(CoreStrings.DuplicateEntityType(entityType.DisplayName()));
            }

            return(ConventionDispatcher.OnEntityTypeAdded(entityType.Builder)?.Metadata);
        }
Example #6
0
        private EntityType AddDelegatedIdentityEntityType(EntityType entityType)
        {
            var entityTypeName = entityType.Name;

            if (_entityTypes.ContainsKey(entityTypeName))
            {
                throw new InvalidOperationException(CoreStrings.ClashingNonDelegatedIdentityEntityType(entityType.DisplayName()));
            }

            if (!_delegatedIdentityEntityTypes.TryGetValue(entityTypeName, out SortedSet <EntityType> entityTypesWithSameType))
            {
                entityTypesWithSameType = new SortedSet <EntityType>(EntityTypePathComparer.Instance);
                _delegatedIdentityEntityTypes[entityTypeName] = entityTypesWithSameType;
            }

            var added = entityTypesWithSameType.Add(entityType);

            Debug.Assert(added);

            return(ConventionDispatcher.OnEntityTypeAdded(entityType.Builder)?.Metadata);
        }
Example #7
0
        public virtual EntityType AddEntityType(
            [NotNull] string name, [CanBeNull] Type type = null, ConfigurationSource configurationSource = ConfigurationSource.Explicit)
        {
            Check.NotEmpty(name, nameof(name));

            var entityType = new EntityType(name, this, configurationSource);

            var previousLength = _entityTypes.Count;

            _entityTypes[name] = entityType;
            if (previousLength == _entityTypes.Count)
            {
                throw new InvalidOperationException(CoreStrings.DuplicateEntityType(entityType.Name));
            }

            if (type != null)
            {
                entityType.ClrType = type;
                _clrTypeMap[type]  = entityType;
            }

            return(ConventionDispatcher.OnEntityTypeAdded(entityType.Builder)?.Metadata);
        }
Example #8
0
        private EntityType AddEntityType(EntityType entityType)
        {
            var entityTypeName = entityType.Name;

            if (entityType.HasDefiningNavigation())
            {
                if (_entityTypes.ContainsKey(entityTypeName))
                {
                    throw new InvalidOperationException(CoreStrings.ClashingNonDependentEntityType(entityType.DisplayName()));
                }

                if (!_entityTypesWithDefiningNavigation.TryGetValue(entityTypeName, out SortedSet <EntityType> entityTypesWithSameType))
                {
                    entityTypesWithSameType = new SortedSet <EntityType>(EntityTypePathComparer.Instance);
                    _entityTypesWithDefiningNavigation[entityTypeName] = entityTypesWithSameType;
                }

                var added = entityTypesWithSameType.Add(entityType);
                Debug.Assert(added);
            }
            else
            {
                if (_entityTypesWithDefiningNavigation.ContainsKey(entityTypeName))
                {
                    throw new InvalidOperationException(CoreStrings.ClashingDependentEntityType(entityType.DisplayName()));
                }

                var previousLength = _entityTypes.Count;
                _entityTypes[entityTypeName] = entityType;
                if (previousLength == _entityTypes.Count)
                {
                    throw new InvalidOperationException(CoreStrings.DuplicateEntityType(entityType.DisplayName()));
                }
            }

            return(ConventionDispatcher.OnEntityTypeAdded(entityType.Builder)?.Metadata);
        }
Example #9
0
        private EntityType AddEntityType(EntityType entityType)
        {
            var entityTypeName = entityType.Name;

            if (entityType.HasDefiningNavigation())
            {
                if (_entityTypes.ContainsKey(entityTypeName))
                {
                    throw new InvalidOperationException(CoreStrings.ClashingNonWeakEntityType(entityType.DisplayName()));
                }

                if (!_entityTypesWithDefiningNavigation.TryGetValue(entityTypeName, out var entityTypesWithSameType))
                {
                    entityTypesWithSameType = new SortedSet <EntityType>(EntityTypePathComparer.Instance);
                    _entityTypesWithDefiningNavigation[entityTypeName] = entityTypesWithSameType;
                }

                var added = entityTypesWithSameType.Add(entityType);
                Debug.Assert(added);
            }
            else
            {
                if (_entityTypesWithDefiningNavigation.ContainsKey(entityTypeName))
                {
                    throw new InvalidOperationException(CoreStrings.ClashingWeakEntityType(entityType.DisplayName()));
                }

                if (AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue12119", out var isEnabled) &&
                    isEnabled)
                {
                    var previousLength = _entityTypes.Count;
                    _entityTypes[entityTypeName] = entityType;
                    if (previousLength == _entityTypes.Count)
                    {
                        throw new InvalidOperationException(CoreStrings.DuplicateEntityType(entityType.DisplayName()));
                    }
                }
                else
                {
                    if (_entityTypes.TryGetValue(entityTypeName, out var clashingEntityType))
                    {
                        if (clashingEntityType.IsQueryType)
                        {
                            if (entityType.IsQueryType)
                            {
                                throw new InvalidOperationException(CoreStrings.DuplicateQueryType(entityType.DisplayName()));
                            }
                            throw new InvalidOperationException(CoreStrings.CannotAccessQueryAsEntity(entityType.DisplayName()));
                        }

                        if (entityType.IsQueryType)
                        {
                            throw new InvalidOperationException(CoreStrings.CannotAccessEntityAsQuery(entityType.DisplayName()));
                        }
                        throw new InvalidOperationException(CoreStrings.DuplicateEntityType(entityType.DisplayName()));
                    }

                    _entityTypes.Add(entityTypeName, entityType);
                }
            }

            return(ConventionDispatcher.OnEntityTypeAdded(entityType.Builder)?.Metadata);
        }