/// <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 InternalRelationshipBuilder WithManyBuilder([CanBeNull] string navigationName) => WithManyBuilder(PropertyIdentity.Create(navigationName));
private OwnedNavigationBuilder <TDependentEntity, TNewRelatedEntity> OwnsManyBuilder <TNewRelatedEntity>(PropertyIdentity navigation) where TNewRelatedEntity : class { InternalRelationshipBuilder relationship; using (var batch = DependentEntityType.Model.ConventionDispatcher.StartBatch()) { relationship = navigation.MemberInfo == null ? DependentEntityType.Builder.Owns(typeof(TNewRelatedEntity), navigation.Name, ConfigurationSource.Explicit) : DependentEntityType.Builder.Owns(typeof(TNewRelatedEntity), (PropertyInfo)navigation.MemberInfo, ConfigurationSource.Explicit); relationship.IsUnique(false, ConfigurationSource.Explicit); relationship = batch.Run(relationship.Metadata).Builder; } return(new OwnedNavigationBuilder <TDependentEntity, TNewRelatedEntity>( DependentEntityType, relationship.Metadata.DeclaringEntityType, relationship)); }
/// <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 InternalRelationshipBuilder WithOneBuilder([CanBeNull] PropertyInfo navigationProperty) => WithOneBuilder(PropertyIdentity.Create(navigationProperty));
private ReferenceOwnershipBuilder <TRelatedEntity, TNewRelatedEntity> OwnsOneBuilder <TNewRelatedEntity>(PropertyIdentity navigation) where TNewRelatedEntity : class { InternalRelationshipBuilder relationship; using (var batch = RelatedEntityType.Model.ConventionDispatcher.StartBatch()) { relationship = navigation.Property == null ? RelatedEntityType.Builder.Owns(typeof(TNewRelatedEntity), navigation.Name, ConfigurationSource.Explicit) : RelatedEntityType.Builder.Owns(typeof(TNewRelatedEntity), (PropertyInfo)navigation.Property, ConfigurationSource.Explicit); relationship.IsUnique(true, ConfigurationSource.Explicit); relationship = batch.Run(relationship.Metadata).Builder; } return(new ReferenceOwnershipBuilder <TRelatedEntity, TNewRelatedEntity>( relationship.Metadata.PrincipalEntityType, relationship.Metadata.DeclaringEntityType, relationship)); }
private OwnedNavigationBuilder <TEntity, TRelatedEntity> OwnsOneBuilder <TRelatedEntity>(PropertyIdentity navigation) where TRelatedEntity : class { InternalRelationshipBuilder relationship; using (var batch = Builder.Metadata.Model.ConventionDispatcher.StartBatch()) { relationship = navigation.MemberInfo == null ? Builder.HasOwnership(typeof(TRelatedEntity), navigation.Name, ConfigurationSource.Explicit) : Builder.HasOwnership(typeof(TRelatedEntity), (PropertyInfo)navigation.MemberInfo, ConfigurationSource.Explicit); relationship.IsUnique(true, ConfigurationSource.Explicit); relationship = batch.Run(relationship.Metadata).Builder; } return(new OwnedNavigationBuilder <TEntity, TRelatedEntity>( Builder.Metadata, relationship.Metadata.DeclaringEntityType, relationship)); }
private InternalRelationshipBuilder WithOneBuilder(PropertyIdentity reference) { var referenceName = reference.Name; if (!Builder.Metadata.IsUnique && Builder.Metadata.PrincipalToDependent != null && Builder.Metadata.GetPrincipalToDependentConfigurationSource() == ConfigurationSource.Explicit && referenceName != null) { ThrowForConflictingNavigation(Builder.Metadata, referenceName, false); } using (var batch = Builder.Metadata.DeclaringEntityType.Model.ConventionDispatcher.StartBatch()) { var builder = Builder.IsUnique(true, ConfigurationSource.Explicit); var foreignKey = builder.Metadata; if (foreignKey.IsSelfReferencing() && referenceName != null && ReferenceName == referenceName) { throw new InvalidOperationException( CoreStrings.ConflictingPropertyOrNavigation( referenceName, RelatedEntityType.DisplayName(), RelatedEntityType.DisplayName())); } var pointsToPrincipal = !foreignKey.IsSelfReferencing() && (!foreignKey.DeclaringEntityType.IsAssignableFrom(DeclaringEntityType) || !foreignKey.PrincipalEntityType.IsAssignableFrom(RelatedEntityType) || (foreignKey.DeclaringEntityType.IsAssignableFrom(RelatedEntityType) && foreignKey.PrincipalEntityType.IsAssignableFrom(DeclaringEntityType) && foreignKey.PrincipalToDependent != null && foreignKey.PrincipalToDependent.Name == ReferenceName)); if (referenceName != null && ((pointsToPrincipal && foreignKey.DependentToPrincipal != null && foreignKey.GetDependentToPrincipalConfigurationSource() == ConfigurationSource.Explicit && foreignKey.DependentToPrincipal.Name != referenceName) || (!pointsToPrincipal && foreignKey.PrincipalToDependent != null && foreignKey.GetPrincipalToDependentConfigurationSource() == ConfigurationSource.Explicit && foreignKey.PrincipalToDependent.Name != referenceName))) { ThrowForConflictingNavigation(foreignKey, referenceName, pointsToPrincipal); } var referenceProperty = reference.MemberInfo; if (referenceName != null && pointsToPrincipal && RelatedEntityType != foreignKey.DeclaringEntityType) { builder = referenceProperty == null && ReferenceProperty == null ? builder.HasNavigations( referenceName, ReferenceName, DeclaringEntityType, RelatedEntityType, ConfigurationSource.Explicit) : builder.HasNavigations( referenceProperty, ReferenceProperty, DeclaringEntityType, RelatedEntityType, ConfigurationSource.Explicit); } else if (referenceName != null && !pointsToPrincipal && RelatedEntityType != foreignKey.PrincipalEntityType) { builder = referenceProperty == null && ReferenceProperty == null ? builder.HasNavigations( ReferenceName, referenceName, RelatedEntityType, DeclaringEntityType, ConfigurationSource.Explicit) : builder.HasNavigations( ReferenceProperty, referenceProperty, RelatedEntityType, DeclaringEntityType, ConfigurationSource.Explicit); } else { if (referenceProperty != null) { builder = builder.HasNavigation( referenceProperty, pointsToPrincipal, ConfigurationSource.Explicit); } else { builder = builder.HasNavigation( referenceName, pointsToPrincipal, ConfigurationSource.Explicit); } } return(batch.Run(builder)); } }