public OwnershipBuilder( IMutableEntityType principalEntityType, IMutableEntityType dependentEntityType, IMutableForeignKey foreignKey) : base(principalEntityType, dependentEntityType, foreignKey) { }
public void It_adds_reads_nav_prop_names() { var modelBuilder = new ModelBuilder(new Metadata.Conventions.ConventionSet()); IMutableForeignKey fk = null; modelBuilder.Entity("A", b => { b.Property <int>("Id"); var key = b.HasKey("Id"); var fkProp = b.Property <int>("ParentId"); fk = b.Metadata.AddForeignKey(fkProp.Metadata, key.Metadata, b.Metadata); }); Assert.Null(fk.Scaffolding().DependentEndNavigation); Assert.Null(fk.Scaffolding().PrincipalEndNavigation); fk.Scaffolding().PrincipalEndNavigation = "PrincipalEnd"; fk.Scaffolding().DependentEndNavigation = "DependentEnd"; Assert.Equal("PrincipalEnd", fk.Scaffolding().PrincipalEndNavigation); Assert.Equal("DependentEnd", fk.Scaffolding().DependentEndNavigation); fk.Scaffolding().PrincipalEndNavigation = null; fk.Scaffolding().DependentEndNavigation = null; Assert.Null(fk.Scaffolding().DependentEndNavigation); Assert.Null(fk.Scaffolding().PrincipalEndNavigation); }
public ReferenceCollectionBuilder( [NotNull] IMutableEntityType principalEntityType, [NotNull] IMutableEntityType dependentEntityType, [NotNull] IMutableForeignKey foreignKey) : base(principalEntityType, dependentEntityType, foreignKey) { }
private static void AssignOnDeleteAction( DatabaseForeignKey databaseForeignKey, IMutableForeignKey foreignKey) { if (databaseForeignKey == null) { throw new ArgumentNullException(nameof(databaseForeignKey)); } if (foreignKey == null) { throw new ArgumentNullException(nameof(foreignKey)); } switch (databaseForeignKey.OnDelete) { case ReferentialAction.Cascade: foreignKey.DeleteBehavior = DeleteBehavior.Cascade; break; case ReferentialAction.SetNull: foreignKey.DeleteBehavior = DeleteBehavior.SetNull; break; default: foreignKey.DeleteBehavior = DeleteBehavior.ClientSetNull; break; } }
public ReferenceReferenceBuilder( IMutableEntityType declaringEntityType, IMutableEntityType relatedEntityType, IMutableForeignKey foreignKey) : base(declaringEntityType, relatedEntityType, foreignKey) { }
protected virtual void AddNavigationProperties([NotNull] IMutableForeignKey foreignKey) { Check.NotNull(foreignKey, nameof(foreignKey)); var dependentEndExistingIdentifiers = ExistingIdentifiers(foreignKey.DeclaringEntityType); var dependentEndNavigationPropertyCandidateName = CandidateNamingService.GetDependentEndCandidateNavigationPropertyName(foreignKey); var dependentEndNavigationPropertyName = CSharpUtilities.Instance.GenerateCSharpIdentifier( dependentEndNavigationPropertyCandidateName, dependentEndExistingIdentifiers, NavigationUniquifier); foreignKey.HasDependentToPrincipal(dependentEndNavigationPropertyName); var principalEndExistingIdentifiers = ExistingIdentifiers(foreignKey.PrincipalEntityType); var principalEndNavigationPropertyCandidateName = foreignKey.IsSelfReferencing() ? string.Format( CultureInfo.CurrentCulture, SelfReferencingPrincipalEndNavigationNamePattern, dependentEndNavigationPropertyName) : CandidateNamingService.GetPrincipalEndCandidateNavigationPropertyName( foreignKey, dependentEndNavigationPropertyName); var principalEndNavigationPropertyName = CSharpUtilities.Instance.GenerateCSharpIdentifier( principalEndNavigationPropertyCandidateName, principalEndExistingIdentifiers, NavigationUniquifier); foreignKey.HasPrincipalToDependent(principalEndNavigationPropertyName); }
public ReferenceNavigationBuilder( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, [CanBeNull] MemberInfo navigationMemberInfo, [NotNull] IMutableForeignKey foreignKey) : base(declaringEntityType, relatedEntityType, navigationMemberInfo, foreignKey) { }
/// <summary> /// <para> /// Finds the first <see cref="IMutableForeignKey" /> that is mapped to the same constraint in a shared table. /// </para> /// <para> /// This method is typically used by database providers (and other extensions). It is generally /// not used in application code. /// </para> /// </summary> /// <param name="foreignKey"> The foreign key. </param> /// <param name="tableName"> The table name. </param> /// <param name="schema"> The schema. </param> /// <param name="principalTableName"> The principal table name. </param> /// <param name="principalSchema"> The principal schema. </param> /// <returns> The foreign key if found, or <see langword="null" /> if none was found.</returns> public static IMutableForeignKey FindSharedTableRootForeignKey( [NotNull] this IMutableForeignKey foreignKey, [NotNull] string tableName, [CanBeNull] string schema, [NotNull] string principalTableName, [CanBeNull] string principalSchema) => (IMutableForeignKey)((IForeignKey)foreignKey).FindSharedTableRootForeignKey( tableName, schema, principalTableName, principalSchema);
public CollectionNavigationBuilder( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, [CanBeNull] string navigationName, [NotNull] IMutableForeignKey foreignKey) : base(declaringEntityType, relatedEntityType, navigationName, foreignKey) { }
public CollectionNavigationBuilder( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, MemberIdentity navigation, [CanBeNull] IMutableForeignKey foreignKey, [CanBeNull] IMutableSkipNavigation skipNavigation) : base(declaringEntityType, relatedEntityType, navigation, foreignKey, skipNavigation) { }
protected RelationshipBuilderBase( [NotNull] IMutableEntityType principalEntityType, [NotNull] IMutableEntityType dependentEntityType, [NotNull] IMutableForeignKey foreignKey) : this(((ForeignKey)foreignKey).Builder, null) { PrincipalEntityType = principalEntityType; DependentEntityType = dependentEntityType; }
protected InvertibleRelationshipBuilderBase( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, [NotNull] IMutableForeignKey foreignKey) : this(((ForeignKey)foreignKey).Builder, null) { DeclaringEntityType = declaringEntityType; RelatedEntityType = relatedEntityType; }
protected InvertibleRelationshipBuilderBase( IMutableEntityType declaringEntityType, IMutableEntityType relatedEntityType, IMutableForeignKey foreignKey) { Builder = ((ForeignKey)foreignKey).Builder; DeclaringEntityType = declaringEntityType; RelatedEntityType = relatedEntityType; }
private static string GetDefaultConstraintName(this IMutableForeignKey metadata, string prefix = DefaultFkPrefix, string principal = null, string dependent = null, string key = null) { principal ??= metadata.PrincipalEntityType.Name; dependent ??= metadata.DeclaringEntityType.Name; key ??= metadata.GetNavigation(true).Name; return($"{prefix}_{dependent}_{principal}_{key}"); }
public ReferenceNavigationBuilder( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, [CanBeNull] string navigationName, [NotNull] IMutableForeignKey foreignKey) { DeclaringEntityType = declaringEntityType; RelatedEntityType = relatedEntityType; ReferenceName = navigationName; Builder = ((ForeignKey)foreignKey).Builder; }
public ReferenceNavigationBuilder( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, [CanBeNull] MemberInfo navigationMemberInfo, [NotNull] IMutableForeignKey foreignKey) { DeclaringEntityType = declaringEntityType; RelatedEntityType = relatedEntityType; ReferenceMember = navigationMemberInfo; ReferenceName = navigationMemberInfo?.GetSimpleMemberName(); Builder = ((ForeignKey)foreignKey).Builder; }
private static string GetDefaultName(IMutableForeignKey key) { var baseName = new StringBuilder() .Append(key.DeclaringEntityType.GetTableName()) .Append("_") .Append(key.PrincipalEntityType.GetTableName()) .Append("_") .AppendJoin("_", key.PrincipalKey.Properties.Select(p => p.GetColumnName())) .Append("_fkey") .ToString(); return(Uniquifier.Truncate(baseName, key.DeclaringEntityType.Model.GetMaxIdentifierLength())); }
public CollectionNavigationBuilder( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, [CanBeNull] string navigationName, [NotNull] IMutableForeignKey foreignKey) { Check.NotNull(foreignKey, nameof(foreignKey)); DeclaringEntityType = declaringEntityType; RelatedEntityType = relatedEntityType; CollectionName = navigationName; Builder = ((ForeignKey)foreignKey).Builder; }
protected virtual void Using([NotNull] IMutableForeignKey rightForeignKey, [NotNull] IMutableForeignKey leftForeignKey) { var leftBuilder = ((SkipNavigation)LeftNavigation).Builder; var rightBuilder = ((SkipNavigation)RightNavigation).Builder; leftBuilder = leftBuilder.HasForeignKey((ForeignKey)leftForeignKey, ConfigurationSource.Explicit); rightBuilder = rightBuilder.HasForeignKey((ForeignKey)rightForeignKey, ConfigurationSource.Explicit); leftBuilder = leftBuilder.HasInverse(rightBuilder.Metadata, ConfigurationSource.Explicit); LeftNavigation = leftBuilder.Metadata; RightNavigation = leftBuilder.Metadata.Inverse; }
protected InvertibleRelationshipBuilderBase( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, [NotNull] IMutableForeignKey foreignKey) : this(((ForeignKey)foreignKey).Builder, null) { Check.NotNull(declaringEntityType, nameof(declaringEntityType)); Check.NotNull(relatedEntityType, nameof(relatedEntityType)); Check.NotNull(foreignKey, nameof(foreignKey)); DeclaringEntityType = declaringEntityType; RelatedEntityType = relatedEntityType; }
protected RelationshipBuilderBase( [NotNull] IMutableEntityType principalEntityType, [NotNull] IMutableEntityType dependentEntityType, [NotNull] IMutableForeignKey foreignKey) { Check.NotNull(principalEntityType, nameof(principalEntityType)); Check.NotNull(dependentEntityType, nameof(dependentEntityType)); Builder = ((ForeignKey)foreignKey).Builder; PrincipalEntityType = principalEntityType; DependentEntityType = dependentEntityType; }
public CollectionNavigationBuilder( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, [CanBeNull] PropertyInfo navigationProperty, [NotNull] IMutableForeignKey foreignKey) { Check.NotNull(foreignKey, nameof(foreignKey)); DeclaringEntityType = declaringEntityType; RelatedEntityType = relatedEntityType; CollectionProperty = navigationProperty; CollectionName = navigationProperty?.GetSimpleMemberName(); Builder = ((ForeignKey)foreignKey).Builder; }
public CollectionNavigationBuilder( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, MemberIdentity navigation, [CanBeNull] IMutableForeignKey foreignKey, [CanBeNull] IMutableSkipNavigation skipNavigation) { DeclaringEntityType = declaringEntityType; RelatedEntityType = relatedEntityType; CollectionMember = navigation.MemberInfo; CollectionName = navigation.Name; Builder = ((ForeignKey)foreignKey)?.Builder; SkipNavigation = skipNavigation; }
/// <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> protected virtual void AddNavigationProperties([NotNull] IMutableForeignKey foreignKey) { Check.NotNull(foreignKey, nameof(foreignKey)); var dependentEndExistingIdentifiers = ExistingIdentifiers(foreignKey.DeclaringEntityType); var dependentEndNavigationPropertyCandidateName = _candidateNamingService.GetDependentEndCandidateNavigationPropertyName(foreignKey); var dependentEndNavigationPropertyName = _cSharpUtilities.GenerateCSharpIdentifier( dependentEndNavigationPropertyCandidateName, dependentEndExistingIdentifiers, singularizePluralizer: null, uniquifier: NavigationUniquifier); foreignKey.SetDependentToPrincipal(dependentEndNavigationPropertyName); if (foreignKey.DeclaringEntityType.IsKeyless) { return; } var principalEndExistingIdentifiers = ExistingIdentifiers(foreignKey.PrincipalEntityType); var principalEndNavigationPropertyCandidateName = foreignKey.IsSelfReferencing() ? string.Format( CultureInfo.CurrentCulture, SelfReferencingPrincipalEndNavigationNamePattern, dependentEndNavigationPropertyName) : _candidateNamingService.GetPrincipalEndCandidateNavigationPropertyName( foreignKey, dependentEndNavigationPropertyName); if (!foreignKey.IsUnique && !foreignKey.IsSelfReferencing()) { principalEndNavigationPropertyCandidateName = _options.NoPluralize ? principalEndNavigationPropertyCandidateName : _pluralizer.Pluralize(principalEndNavigationPropertyCandidateName); } var principalEndNavigationPropertyName = _cSharpUtilities.GenerateCSharpIdentifier( principalEndNavigationPropertyCandidateName, principalEndExistingIdentifiers, singularizePluralizer: null, uniquifier: NavigationUniquifier); foreignKey.SetPrincipalToDependent(principalEndNavigationPropertyName); }
/// <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 AddNavigationProperties(IMutableForeignKey foreignKey) { if (foreignKey == null) { throw new ArgumentNullException(nameof(foreignKey)); } var dependentEndExistingIdentifiers = ExistingIdentifiers(foreignKey.DeclaringEntityType); var dependentEndNavigationPropertyCandidateName = _candidateNamingService.GetDependentEndCandidateNavigationPropertyName(foreignKey); var dependentEndNavigationPropertyName = _cSharpUtilities.GenerateCSharpIdentifier( dependentEndNavigationPropertyCandidateName, dependentEndExistingIdentifiers, singularizePluralizer: null, uniquifier: NavigationUniquifier); foreignKey.HasDependentToPrincipal(dependentEndNavigationPropertyName); var principalEndExistingIdentifiers = ExistingIdentifiers(foreignKey.PrincipalEntityType); var principalEndNavigationPropertyCandidateName = foreignKey.IsSelfReferencing() ? string.Format( CultureInfo.CurrentCulture, SelfReferencingPrincipalEndNavigationNamePattern, dependentEndNavigationPropertyName) : _candidateNamingService.GetPrincipalEndCandidateNavigationPropertyName( foreignKey, dependentEndNavigationPropertyName); if (!foreignKey.IsUnique && !foreignKey.IsSelfReferencing()) { principalEndNavigationPropertyCandidateName = _pluralizer.Pluralize(principalEndNavigationPropertyCandidateName); } var principalEndNavigationPropertyName = _cSharpUtilities.GenerateCSharpIdentifier( principalEndNavigationPropertyCandidateName, principalEndExistingIdentifiers, singularizePluralizer: null, uniquifier: NavigationUniquifier); foreignKey.HasPrincipalToDependent(principalEndNavigationPropertyName); }
private static void AssignOnDeleteAction( [NotNull] DatabaseForeignKey databaseForeignKey, [NotNull] IMutableForeignKey foreignKey) { Check.NotNull(databaseForeignKey, nameof(databaseForeignKey)); Check.NotNull(foreignKey, nameof(foreignKey)); switch (databaseForeignKey.OnDelete) { case ReferentialAction.Cascade: foreignKey.DeleteBehavior = DeleteBehavior.Cascade; break; case ReferentialAction.SetNull: foreignKey.DeleteBehavior = DeleteBehavior.SetNull; break; default: foreignKey.DeleteBehavior = DeleteBehavior.ClientSetNull; break; } }
private static void AssignOnDeleteAction( [NotNull] ForeignKeyModel fkModel, [NotNull] IMutableForeignKey foreignKey) { Check.NotNull(fkModel, nameof(fkModel)); Check.NotNull(foreignKey, nameof(foreignKey)); switch (fkModel.OnDelete) { case ReferentialAction.Cascade: foreignKey.DeleteBehavior = DeleteBehavior.Cascade; break; case ReferentialAction.SetNull: foreignKey.DeleteBehavior = DeleteBehavior.SetNull; break; default: foreignKey.DeleteBehavior = DeleteBehavior.Restrict; break; } }
/// <summary> /// Sets the foreign key constraint name. /// </summary> /// <param name="foreignKey"> The foreign key. </param> /// <param name="value"> The value to set. </param> public static void SetConstraintName([NotNull] this IMutableForeignKey foreignKey, [CanBeNull] string value) => foreignKey.SetOrRemoveAnnotation( RelationalAnnotationNames.Name, Check.NullButNotEmpty(value, nameof(value)));
/// <summary> /// Gets the entity type related to the given one. /// </summary> /// <param name="foreignKey"> The foreign key. </param> /// <param name="entityType"> One of the entity types related by the foreign key. </param> /// <returns> The entity type related to the given one. </returns> public static IMutableEntityType GetRelatedEntityType( [NotNull] this IMutableForeignKey foreignKey, [NotNull] IMutableEntityType entityType) => (IMutableEntityType)((IForeignKey)foreignKey).GetRelatedEntityType(entityType);
/// <summary> /// Returns a navigation associated with this foreign key. /// </summary> /// <param name="foreignKey"> The foreign key. </param> /// <param name="pointsToPrincipal"> /// A value indicating whether the navigation is on the dependent type pointing to the principal type. /// </param> /// <returns> /// A navigation associated with this foreign key or <c>null</c>. /// </returns> public static IMutableNavigation GetNavigation([NotNull] this IMutableForeignKey foreignKey, bool pointsToPrincipal) => pointsToPrincipal ? foreignKey.DependentToPrincipal : foreignKey.PrincipalToDependent;