Skip to content

Annotate the remainder of metadata for nullability #23905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/EFCore.Relational/Metadata/IConventionDbFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction
/// <exception cref="InvalidOperationException"> If the function has been removed from the model. </exception>
new IConventionDbFunctionBuilder Builder { get; }

/// <summary>
/// Indicates whether this function is in a model, i.e. hasn't been removed from one.
/// </summary>
new bool IsInModel { get; }

/// <summary>
/// Gets the configuration source for this function.
/// </summary>
Expand Down
5 changes: 0 additions & 5 deletions src/EFCore.Relational/Metadata/IConventionSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public interface IConventionSequence : ISequence, IConventionAnnotatable
/// <exception cref="InvalidOperationException"> If the sequence has been removed from the model. </exception>
new IConventionSequenceBuilder Builder { get; }

/// <summary>
/// Indicates whether this sequence is in a model, i.e. hasn't been removed from one.
/// </summary>
new bool IsInModel { get; }

/// <summary>
/// Gets the configuration source for this <see cref="IConventionSequence" />.
/// </summary>
Expand Down
9 changes: 4 additions & 5 deletions src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,12 @@ private InternalForeignKeyBuilder WithOneBuilder(MemberIdentity reference)
/// <returns> An object to further configure the relationship. </returns>
public virtual CollectionCollectionBuilder WithMany([NotNull] string navigationName)
{
if (Builder != null
&& Builder.Metadata.PrincipalToDependent == null)
if (Builder?.Metadata.PrincipalToDependent == null)
{
throw new InvalidOperationException(
CoreStrings.MissingInverseManyToManyNavigation(
Builder.Metadata.PrincipalEntityType.DisplayName(),
Builder.Metadata.DeclaringEntityType.DisplayName()));
Builder?.Metadata.PrincipalEntityType.DisplayName(),
Builder?.Metadata.DeclaringEntityType.DisplayName()));
}

var leftName = Builder?.Metadata.PrincipalToDependent!.Name;
Expand Down Expand Up @@ -322,7 +321,7 @@ protected virtual IMutableSkipNavigation WithLeftManyNavigation([NotNull] string
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[EntityFrameworkInternal]
protected virtual IMutableSkipNavigation WithRightManyNavigation([NotNull] string navigationName, [CanBeNull] string? inverseName)
protected virtual IMutableSkipNavigation WithRightManyNavigation([NotNull] string navigationName, [NotNull] string inverseName)
=> WithRightManyNavigation(MemberIdentity.Create(navigationName), inverseName);

/// <summary>
Expand Down
12 changes: 10 additions & 2 deletions src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,17 @@ public virtual ReferenceCollectionBuilder<TEntity, TRelatedEntity> WithOne(
/// The name of the collection navigation property on the other end of this relationship.
/// </param>
/// <returns> An object to further configure the relationship. </returns>
public new virtual CollectionCollectionBuilder<TRelatedEntity, TEntity> WithMany([NotNull] string navigationName)
public new virtual CollectionCollectionBuilder<TRelatedEntity, TEntity>? WithMany([NotNull] string navigationName)
{
var leftName = Builder?.Metadata.PrincipalToDependent!.Name;
if (Builder?.Metadata.PrincipalToDependent == null)
{
throw new InvalidOperationException(
CoreStrings.MissingInverseManyToManyNavigation(
Builder?.Metadata.PrincipalEntityType.DisplayName(),
Builder?.Metadata.DeclaringEntityType.DisplayName()));
}

var leftName = Builder.Metadata.PrincipalToDependent.Name;
var collectionCollectionBuilder =
new CollectionCollectionBuilder<TRelatedEntity, TEntity>(
RelatedEntityType,
Expand Down
5 changes: 2 additions & 3 deletions src/EFCore/Metadata/Conventions/IConventionBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ public interface IConventionBatch : IDisposable
/// </summary>
/// <param name="foreignKey"> The foreign key to track. </param>
/// <returns>
/// An object that will contain the reference to the new foreign key instance
/// if the given one was replaced by a convention.
/// An object that will contain the reference to the new foreign key instance if the given one was replaced by a convention.
/// Otherwise, returns the original foreign key.
/// </returns>
// TODO-NULLABLE: does this ever refer null (as is implied by the comment?)
IMetadataReference<IConventionForeignKey> Track([NotNull] IConventionForeignKey foreignKey);
}
}
15 changes: 10 additions & 5 deletions src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,10 @@ public virtual bool CanSetKeyValueComparer([CanBeNull] ValueComparer? comparer,
/// 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 virtual InternalPropertyBuilder Attach([NotNull] InternalEntityTypeBuilder entityTypeBuilder)
public virtual InternalPropertyBuilder? Attach([NotNull] InternalEntityTypeBuilder entityTypeBuilder)
{
var newProperty = entityTypeBuilder.Metadata.FindProperty(Metadata.Name);
InternalPropertyBuilder newPropertyBuilder;
InternalPropertyBuilder? newPropertyBuilder;
var configurationSource = Metadata.GetConfigurationSource();
var typeConfigurationSource = Metadata.GetTypeConfigurationSource();
if (newProperty != null
Expand All @@ -605,10 +605,15 @@ public virtual InternalPropertyBuilder Attach([NotNull] InternalEntityTypeBuilde

newPropertyBuilder = identifyingMemberInfo == null
? entityTypeBuilder.Property(
Metadata.ClrType, Metadata.Name, Metadata.GetTypeConfigurationSource(), configurationSource)!
Metadata.ClrType, Metadata.Name, Metadata.GetTypeConfigurationSource(), configurationSource)
: (identifyingMemberInfo as PropertyInfo)?.IsIndexerProperty() == true
? entityTypeBuilder.IndexerProperty(Metadata.ClrType, Metadata.Name, configurationSource)!
: entityTypeBuilder.Property(identifyingMemberInfo, configurationSource!)!;
? entityTypeBuilder.IndexerProperty(Metadata.ClrType, Metadata.Name, configurationSource)
: entityTypeBuilder.Property(identifyingMemberInfo, configurationSource!);

if (newPropertyBuilder is null)
{
return null;
}
}

if (newProperty == Metadata)
Expand Down