예제 #1
0
    /// <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>
    public Trigger(
        IMutableEntityType entityType,
        string name,
        string?tableName,
        string?tableSchema,
        ConfigurationSource configurationSource)
    {
        EntityType           = entityType;
        ModelName            = name;
        _tableName           = tableName;
        _tableSchema         = tableSchema;
        _configurationSource = configurationSource;

        var triggers = GetTriggersDictionary(entityType);

        if (triggers == null)
        {
            triggers = new SortedDictionary <string, ITrigger>(StringComparer.Ordinal);
            entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.Triggers, triggers);
        }

        if (triggers.ContainsKey(name))
        {
            throw new InvalidOperationException(
                      RelationalStrings.DuplicateTrigger(
                          name, entityType.DisplayName(), entityType.DisplayName()));
        }

        var baseTrigger = entityType.BaseType?.FindTrigger(name);

        if (baseTrigger != null)
        {
            throw new InvalidOperationException(
                      RelationalStrings.DuplicateTrigger(
                          name, entityType.DisplayName(), baseTrigger.EntityType.DisplayName()));
        }

        foreach (var derivedType in entityType.GetDerivedTypes())
        {
            var derivedTrigger = FindTrigger(derivedType, name);
            if (derivedTrigger != null)
            {
                throw new InvalidOperationException(
                          RelationalStrings.DuplicateTrigger(
                              name, entityType.DisplayName(), derivedTrigger.EntityType.DisplayName()));
            }
        }

        if (entityType.GetTableName() is null)
        {
            throw new InvalidOperationException(RelationalStrings.TriggerOnUnmappedEntityType(name, entityType.DisplayName()));
        }

        EnsureMutable();

        triggers.Add(name, this);

        _builder = new InternalTriggerBuilder(this, ((IConventionModel)entityType.Model).Builder);
    }
예제 #2
0
        /// <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>
        public CheckConstraint(
            IMutableEntityType entityType,
            string name,
            string sql,
            ConfigurationSource configurationSource)
        {
            Check.NotNull(entityType, nameof(entityType));
            Check.NotEmpty(name, nameof(name));
            Check.NotEmpty(sql, nameof(sql));

            EntityType           = entityType;
            ModelName            = name;
            Sql                  = sql;
            _configurationSource = configurationSource;

            var constraints = GetConstraintsDictionary(EntityType);

            if (constraints == null)
            {
                constraints = new SortedDictionary <string, ICheckConstraint>(StringComparer.Ordinal);
                ((IMutableEntityType)EntityType).SetOrRemoveAnnotation(RelationalAnnotationNames.CheckConstraints, constraints);
            }

            if (constraints.ContainsKey(name))
            {
                throw new InvalidOperationException(
                          RelationalStrings.DuplicateCheckConstraint(
                              name, EntityType.DisplayName(), EntityType.DisplayName()));
            }

            var baseCheckConstraint = entityType.BaseType?.FindCheckConstraint(name);

            if (baseCheckConstraint != null)
            {
                throw new InvalidOperationException(
                          RelationalStrings.DuplicateCheckConstraint(
                              name, EntityType.DisplayName(), baseCheckConstraint.EntityType.DisplayName()));
            }

            foreach (var derivedType in entityType.GetDerivedTypes())
            {
                var derivedCheckConstraint = FindCheckConstraint(derivedType, name);
                if (derivedCheckConstraint != null)
                {
                    throw new InvalidOperationException(
                              RelationalStrings.DuplicateCheckConstraint(
                                  name, EntityType.DisplayName(), derivedCheckConstraint.EntityType.DisplayName()));
                }
            }

            EnsureMutable();

            constraints.Add(name, this);

            _builder = new InternalCheckConstraintBuilder(this, ((IConventionModel)entityType.Model).Builder);
        }
예제 #3
0
    public CollectionCollectionBuilder(
        IMutableEntityType leftEntityType,
        IMutableEntityType rightEntityType,
        IMutableSkipNavigation leftNavigation,
        IMutableSkipNavigation rightNavigation)
    {
        Check.DebugAssert(((IConventionEntityType)leftEntityType).IsInModel, "Not in model");
        Check.DebugAssert(((IConventionEntityType)rightEntityType).IsInModel, "Not in model");
        Check.DebugAssert(((IConventionSkipNavigation)leftNavigation).IsInModel, "Not in model");
        Check.DebugAssert(((IConventionSkipNavigation)rightNavigation).IsInModel, "Not in model");

        if (leftNavigation == rightNavigation)
        {
            throw new InvalidOperationException(
                      CoreStrings.ManyToManyOneNav(leftEntityType.DisplayName(), leftNavigation.Name));
        }

        LeftEntityType  = leftEntityType;
        RightEntityType = rightEntityType;
        LeftNavigation  = leftNavigation;
        RightNavigation = rightNavigation;

        var leftSkipNavigation  = (SkipNavigation)leftNavigation;
        var rightSkipNavigation = (SkipNavigation)rightNavigation;

        leftSkipNavigation.Builder.HasInverse(rightSkipNavigation, ConfigurationSource.Explicit);

        // We delayed setting the ConfigurationSource of SkipNavigation in HasMany().
        // But now we know that both navigations are skip navigations.
        leftSkipNavigation.UpdateConfigurationSource(ConfigurationSource.Explicit);
        rightSkipNavigation.UpdateConfigurationSource(ConfigurationSource.Explicit);
    }
        /// <summary>
        ///     Adds a property backed up by an indexer to this entity type.
        /// </summary>
        /// <param name="entityType"> The entity type to add the property to. </param>
        /// <param name="name"> The name of the property to add. </param>
        /// <param name="propertyType"> The type of value the property will hold. </param>
        /// <returns> The newly created property. </returns>
        public static IMutableProperty AddIndexerProperty(
            [NotNull] this IMutableEntityType entityType, [NotNull] string name, [NotNull] Type propertyType)
        {
            Check.NotNull(entityType, nameof(entityType));

            var indexerPropertyInfo = entityType.FindIndexerPropertyInfo();

            if (indexerPropertyInfo == null)
            {
                throw new InvalidOperationException(
                          CoreStrings.NonIndexerEntityType(name, entityType.DisplayName(), typeof(string).ShortDisplayName()));
            }

            return(entityType.AddProperty(name, propertyType, indexerPropertyInfo));
        }
        /// <summary>
        ///     Adds a property to this entity.
        /// </summary>
        /// <param name="entityType"> The entity type to add the property to. </param>
        /// <param name="propertyInfo"> The corresponding property in the entity class. </param>
        /// <returns> The newly created property. </returns>
        public static IMutableProperty AddProperty(
            [NotNull] this IMutableEntityType entityType, [NotNull] PropertyInfo propertyInfo)
        {
            Check.NotNull(entityType, nameof(entityType));
            Check.NotNull(propertyInfo, nameof(propertyInfo));

            if (entityType.HasClrType() &&
                !propertyInfo.DeclaringType.GetTypeInfo().IsAssignableFrom(entityType.ClrType.GetTypeInfo()))
            {
                throw new ArgumentException(CoreStrings.PropertyWrongEntityClrType(
                                                propertyInfo.Name, entityType.DisplayName(), propertyInfo.DeclaringType.Name));
            }

            var property = entityType.AddProperty(propertyInfo.Name, propertyInfo.PropertyType);

            property.IsShadowProperty = false;
            return(property);
        }
예제 #6
0
        /// <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>
        public CheckConstraint(
            [NotNull] IMutableEntityType entityType,
            [NotNull] string name,
            [NotNull] string sql,
            ConfigurationSource configurationSource)
        {
            Check.NotNull(entityType, nameof(entityType));
            Check.NotEmpty(name, nameof(name));
            Check.NotEmpty(sql, nameof(sql));

            EntityType           = entityType;
            Name                 = name;
            Sql                  = sql;
            _configurationSource = configurationSource;

            var dataDictionary = GetConstraintsDictionary(EntityType);

            if (dataDictionary == null)
            {
                dataDictionary = new Dictionary <string, CheckConstraint>();
                ((IMutableEntityType)EntityType).SetOrRemoveAnnotation(RelationalAnnotationNames.CheckConstraints, dataDictionary);
            }

            if (dataDictionary.ContainsKey(Name))
            {
                throw new InvalidOperationException(RelationalStrings.DuplicateCheckConstraint(Name, EntityType.DisplayName()));
            }

            dataDictionary.Add(name, this);
        }
예제 #7
0
        /// <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>
        public CheckConstraint(
            IMutableEntityType entityType,
            string name,
            string sql,
            ConfigurationSource configurationSource)
        {
            Check.NotNull(entityType, nameof(entityType));
            Check.NotEmpty(name, nameof(name));
            Check.NotEmpty(sql, nameof(sql));

            EntityType           = entityType;
            Name                 = name;
            Sql                  = sql;
            _configurationSource = configurationSource;

            var constraints = GetConstraintsDictionary(EntityType);

            if (constraints == null)
            {
                constraints = new SortedDictionary <string, ICheckConstraint>();
                ((IMutableEntityType)EntityType).SetOrRemoveAnnotation(RelationalAnnotationNames.CheckConstraints, constraints);
            }

            if (constraints.ContainsKey(Name))
            {
                throw new InvalidOperationException(RelationalStrings.DuplicateCheckConstraint(Name, EntityType.DisplayName()));
            }

            EnsureMutable();

            constraints.Add(name, this);
        }