Skip to content
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

Annotate metadata for nullability, leaving only builders and conventions #23381

Merged
11 commits merged into from
Nov 19, 2020
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal
{
/// <summary>
roji marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -27,11 +29,11 @@ public static bool IsOrdinalKeyProperty([NotNull] this IProperty property)
property.DeclaringEntityType.IsOwned(), $"Expected {property.DeclaringEntityType.DisplayName()} to be owned.");
Check.DebugAssert(property.GetJsonPropertyName().Length == 0, $"Expected {property.Name} to be non-persisted.");

return property.IsPrimaryKey()
return property.FindContainingPrimaryKey() is IKey key
&& key.Properties.Count > 1
&& !property.IsForeignKey()
&& property.ClrType == typeof(int)
&& property.ValueGenerated == ValueGenerated.OnAdd
&& property.DeclaringEntityType.FindPrimaryKey().Properties.Count > 1;
&& property.ValueGenerated == ValueGenerated.OnAdd;
}
}
}
92 changes: 47 additions & 45 deletions src/EFCore.Relational/Extensions/RelationalModelExtensions.cs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/EFCore.Relational/Metadata/CheckConstraintExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Metadata/ColumnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Metadata/ColumnMappingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Metadata/DbFunctionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Metadata/FunctionColumnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Metadata/FunctionMappingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Metadata/ICheckConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using Microsoft.EntityFrameworkCore.Infrastructure;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
12 changes: 7 additions & 5 deletions src/EFCore.Relational/Metadata/IColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Collections.Generic;
using System.Linq;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down Expand Up @@ -65,7 +67,7 @@ bool IsRowVersion
/// <summary>
/// Returns the object that is used as the default value for this column.
/// </summary>
public virtual object DefaultValue
public virtual object? DefaultValue
{
get
{
Expand All @@ -82,14 +84,14 @@ public virtual object DefaultValue
/// <summary>
/// Returns the SQL expression that is used as the default value for this column.
/// </summary>
public virtual string DefaultValueSql
public virtual string? DefaultValueSql
=> PropertyMappings.First().Property
.GetDefaultValueSql(StoreObjectIdentifier.Table(Table.Name, Table.Schema));

/// <summary>
/// Returns the SQL expression that is used as the computed value for this column.
/// </summary>
public virtual string ComputedColumnSql
public virtual string? ComputedColumnSql
=> PropertyMappings.First().Property
.GetComputedColumnSql(StoreObjectIdentifier.Table(Table.Name, Table.Schema));

Expand All @@ -104,14 +106,14 @@ public virtual bool? IsStored
/// <summary>
/// Comment for this column
/// </summary>
public virtual string Comment
public virtual string? Comment
=> PropertyMappings.First().Property
.GetComment(StoreObjectIdentifier.Table(Table.Name, Table.Schema));

/// <summary>
/// Collation for this column
/// </summary>
public virtual string Collation
public virtual string? Collation
=> PropertyMappings.First().Property
.GetCollation(StoreObjectIdentifier.Table(Table.Name, Table.Schema));
}
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Metadata/IColumnBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Infrastructure;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Metadata/IColumnMapping.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Metadata/IColumnMappingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand Down
16 changes: 9 additions & 7 deletions src/EFCore.Relational/Metadata/IConventionDbFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Storage;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand All @@ -24,7 +26,7 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction
/// <summary>
/// Gets the builder that can be used to configure this function.
/// </summary>
new IConventionDbFunctionBuilder Builder { get; }
new IConventionDbFunctionBuilder? Builder { get; }

/// <summary>
/// Gets the configuration source for this function.
Expand All @@ -38,7 +40,7 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction
/// <param name="name"> The name of the function in the database. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> The configured value. </returns>
string SetName([CanBeNull] string name, bool fromDataAnnotation = false);
string? SetName([CanBeNull] string? name, bool fromDataAnnotation = false);

/// <summary>
/// Gets the configuration source for <see cref="IDbFunction.Name" />.
Expand All @@ -52,7 +54,7 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction
/// <param name="schema"> The schema of the function in the database. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> The configured value. </returns>
string SetSchema([CanBeNull] string schema, bool fromDataAnnotation = false);
string? SetSchema([CanBeNull] string? schema, bool fromDataAnnotation = false);

/// <summary>
/// Gets the configuration source for <see cref="IDbFunction.Schema" />.
Expand Down Expand Up @@ -94,7 +96,7 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction
/// <param name="storeType"> The store type of the function in the database. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> The configured value. </returns>
string SetStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false);
string? SetStoreType([CanBeNull] string? storeType, bool fromDataAnnotation = false);

/// <summary>
/// Gets the configuration source for <see cref="IDbFunction.StoreType" />.
Expand All @@ -108,7 +110,7 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction
/// <param name="typeMapping"> The type mapping of the function in the database. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> The configured value. </returns>
RelationalTypeMapping SetTypeMapping([CanBeNull] RelationalTypeMapping typeMapping, bool fromDataAnnotation = false);
RelationalTypeMapping? SetTypeMapping([CanBeNull] RelationalTypeMapping? typeMapping, bool fromDataAnnotation = false);

/// <summary>
/// Gets the configuration source for <see cref="IDbFunction.TypeMapping" />.
Expand All @@ -124,8 +126,8 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction
/// </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> The configured value. </returns>
Func<IReadOnlyCollection<SqlExpression>, SqlExpression> SetTranslation(
[CanBeNull] Func<IReadOnlyCollection<SqlExpression>, SqlExpression> translation,
Func<IReadOnlyCollection<SqlExpression>, SqlExpression>? SetTranslation(
[CanBeNull] Func<IReadOnlyCollection<SqlExpression>, SqlExpression>? translation,
bool fromDataAnnotation = false);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Storage;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand All @@ -20,7 +22,7 @@ public interface IConventionDbFunctionParameter : IConventionAnnotatable, IDbFun
/// <summary>
/// The <see cref="IConventionDbFunctionParameterBuilder" /> for configuring this function parameter.
/// </summary>
new IConventionDbFunctionParameterBuilder Builder { get; }
new IConventionDbFunctionParameterBuilder? Builder { get; }

/// <summary>
/// Returns the configuration source for the parameter.
Expand All @@ -33,7 +35,7 @@ public interface IConventionDbFunctionParameter : IConventionAnnotatable, IDbFun
/// </summary>
/// <param name="storeType"> The store type of the parameter. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
string SetStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false);
string? SetStoreType([CanBeNull] string? storeType, bool fromDataAnnotation = false);

/// <summary>
/// Returns the configuration source for <see cref="IDbFunctionParameter.StoreType" />.
Expand All @@ -46,7 +48,7 @@ public interface IConventionDbFunctionParameter : IConventionAnnotatable, IDbFun
/// </summary>
/// <param name="typeMapping"> The type mapping of the parameter in the database. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
RelationalTypeMapping SetTypeMapping([CanBeNull] RelationalTypeMapping typeMapping, bool fromDataAnnotation = false);
RelationalTypeMapping? SetTypeMapping([CanBeNull] RelationalTypeMapping? typeMapping, bool fromDataAnnotation = false);

/// <summary>
/// Returns the configuration source for <see cref="IDbFunctionParameter.TypeMapping" />.
Expand Down
8 changes: 5 additions & 3 deletions src/EFCore.Relational/Metadata/IConventionSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
Expand All @@ -21,7 +23,7 @@ public interface IConventionSequence : ISequence, IConventionAnnotatable
/// <summary>
/// Gets the builder that can be used to configure this sequence.
/// </summary>
new IConventionSequenceBuilder Builder { get; }
new IConventionSequenceBuilder? Builder { get; }

/// <summary>
/// Gets the configuration source for this <see cref="IConventionSequence" />.
Expand Down Expand Up @@ -91,7 +93,7 @@ public interface IConventionSequence : ISequence, IConventionAnnotatable
/// <param name="type"> The <see cref="Type" /> of values returned by the sequence. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> The configured value. </returns>
Type SetType([CanBeNull] Type type, bool fromDataAnnotation = false);
Type? SetType([CanBeNull] Type? type, bool fromDataAnnotation = false);

/// <summary>
/// Gets the configuration source for <see cref="ISequence.ClrType" />.
Expand All @@ -106,7 +108,7 @@ public interface IConventionSequence : ISequence, IConventionAnnotatable
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> The configured value. </returns>
[Obsolete("Use SetType")]
Type SetClrType([CanBeNull] Type type, bool fromDataAnnotation = false);
Type? SetClrType([CanBeNull] Type? type, bool fromDataAnnotation = false);

/// <summary>
/// Gets the configuration source for <see cref="ISequence.ClrType" />.
Expand Down
Loading