/// <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); }
/// <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); }
private void PrefixEntitiesRecursive(IMutableEntityType entity, TablePrefixAttribute entityPrefixAttribute, string tableName) { entity.Relational().TableName = tableName; PrefixColumnNames(entity, entityPrefixAttribute?.NamespacePrefix, entityPrefixAttribute?.ColumnPrefix); foreach (var child in entity.GetDerivedTypes()) { var childPrefixAttribute = GetTablePrefixAttribute(child); PrefixEntitiesRecursive(child, childPrefixAttribute, tableName); } }
private void PrefixEntitiesRecursive(IMutableEntityType entity, TablePrefixAttribute entityPrefixAttribute, string tableName) { if (entity.BaseType == null) { entity.SetTableName(tableName); } PrefixColumnNames(entity, entityPrefixAttribute?.NamespacePrefix, entityPrefixAttribute?.ColumnPrefix); foreach (var child in entity.GetDerivedTypes()) { if (child.BaseType != entity) { continue; } var childPrefixAttribute = GetTablePrefixAttribute(child); PrefixEntitiesRecursive(child, childPrefixAttribute, tableName); } }