Skip to content

Commit

Permalink
Annotate for nullability
Browse files Browse the repository at this point in the history
Sync to EFCore 6.0.0-preview.3.21165.3
(3d6009b84224ba009143dfe8e08a4198acdc0afe)

Closes #1552
  • Loading branch information
roji committed Mar 16, 2021
1 parent 731887a commit b6a6859
Show file tree
Hide file tree
Showing 150 changed files with 2,302 additions and 2,715 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<EFCoreVersion>6.0.0-preview.3.21163.3</EFCoreVersion>
<EFCoreVersion>6.0.0-preview.3.21165.3</EFCoreVersion>
<MicrosoftExtensionsVersion>6.0.0-preview.3.21164.8</MicrosoftExtensionsVersion>
<NpgsqlVersion>6.0.0-ci.20210310T201503</NpgsqlVersion>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public static class NpgsqlNetTopologySuiteDbContextOptionsBuilderExtensions
/// </returns>
public static NpgsqlDbContextOptionsBuilder UseNetTopologySuite(
[NotNull] this NpgsqlDbContextOptionsBuilder optionsBuilder,
[CanBeNull] CoordinateSequenceFactory coordinateSequenceFactory = null,
[CanBeNull] PrecisionModel precisionModel = null,
[CanBeNull] CoordinateSequenceFactory? coordinateSequenceFactory = null,
[CanBeNull] PrecisionModel? precisionModel = null,
Ordinates handleOrdinates = Ordinates.None,
bool geographyAsDefault = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class NpgsqlNetTopologySuiteDbFunctionsExtensions
///
/// See https://postgis.net/docs/ST_Transform.html.
/// </remarks>
public static TGeometry Transform<TGeometry>([CanBeNull] this DbFunctions _, [NotNull] TGeometry geometry, int srid)
public static TGeometry Transform<TGeometry>([NotNull] this DbFunctions _, [NotNull] TGeometry geometry, int srid)
where TGeometry : Geometry
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Transform)));

Expand All @@ -28,7 +28,7 @@ public static TGeometry Transform<TGeometry>([CanBeNull] this DbFunctions _, [No
/// <param name="distance">The distance value to compare.</param>
/// <param name="useSpheroid">Whether to use sphere or spheroid distance measurement.</param>
/// <returns>True if the geometries are less than distance apart.</returns>
public static bool IsWithinDistance([CanBeNull] this DbFunctions _, [NotNull] Geometry geometry, [NotNull] Geometry anotherGeometry, double distance, bool useSpheroid)
public static bool IsWithinDistance([NotNull] this DbFunctions _, [NotNull] Geometry geometry, [NotNull] Geometry anotherGeometry, double distance, bool useSpheroid)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(IsWithinDistance)));

/// <summary>
Expand All @@ -39,7 +39,7 @@ public static bool IsWithinDistance([CanBeNull] this DbFunctions _, [NotNull] Ge
/// <param name="useSpheroid">Whether to use sphere or spheroid distance measurement.</param>
/// <returns>The distance between the geometries.</returns>
/// <exception cref="ArgumentException">If g is null</exception>
public static double Distance([CanBeNull] this DbFunctions _, [NotNull] Geometry geometry, [NotNull] Geometry anotherGeometry, bool useSpheroid)
public static double Distance([NotNull] this DbFunctions _, [NotNull] Geometry geometry, [NotNull] Geometry anotherGeometry, bool useSpheroid)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Distance)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static class NpgsqlNetTopologySuiteServiceCollectionExtensions
Check.NotNull(serviceCollection, nameof(serviceCollection));

new EntityFrameworkRelationalServicesBuilder(serviceCollection)
.TryAdd<ISingletonOptions, INpgsqlNetTopologySuiteOptions>(p => p.GetService<INpgsqlNetTopologySuiteOptions>())
.TryAdd<ISingletonOptions, INpgsqlNetTopologySuiteOptions>(p => p.GetRequiredService<INpgsqlNetTopologySuiteOptions>())
.TryAddProviderSpecificServices(
x => x
.TryAddSingletonEnumerable<IRelationalTypeMappingSourcePlugin, NpgsqlNetTopologySuiteTypeMappingSourcePlugin>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal
{
public class NpgsqlNetTopologySuiteOptionsExtension : IDbContextOptionsExtension
{
DbContextOptionsExtensionInfo _info;
DbContextOptionsExtensionInfo? _info;

public virtual bool IsGeographyDefault { get; private set; }

Expand Down Expand Up @@ -61,7 +61,7 @@ public virtual void Validate(IDbContextOptions options)

sealed class ExtensionInfo : DbContextOptionsExtensionInfo
{
string _logFragment;
string? _logFragment;

public ExtensionInfo(IDbContextOptionsExtension extension)
: base(extension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,20 @@ public class NpgsqlGeometryMemberTranslator : IMemberTranslator
};
}

public virtual SqlExpression Translate(
SqlExpression instance,
public virtual SqlExpression? Translate(
SqlExpression? instance,
MemberInfo member,
Type returnType,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
var declaringType = member.DeclaringType;

if (!typeof(Geometry).IsAssignableFrom(declaringType))
if (instance is null || !typeof(Geometry).IsAssignableFrom(declaringType))
return null;

var typeMapping = instance.TypeMapping;
Debug.Assert(typeMapping != null, "Instance must have typeMapping assigned.");
var storeType = instance.TypeMapping.StoreType;
var resultGeometryTypeMapping = typeof(Geometry).IsAssignableFrom(returnType)
? _typeMappingSource.FindMapping(returnType, storeType)
: null;
var storeType = instance.TypeMapping!.StoreType;

if (typeof(Point).IsAssignableFrom(declaringType))
{
Expand All @@ -108,13 +105,13 @@ public class NpgsqlGeometryMemberTranslator : IMemberTranslator
return member.Name switch
{
nameof(Geometry.Area) => Function("ST_Area", new[] { instance }, typeof(double)),
nameof(Geometry.Boundary) => Function("ST_Boundary", new[] { instance }, typeof(Geometry), resultGeometryTypeMapping),
nameof(Geometry.Centroid) => Function("ST_Centroid", new[] { instance }, typeof(Point), resultGeometryTypeMapping),
nameof(Geometry.Boundary) => Function("ST_Boundary", new[] { instance }, typeof(Geometry), ResultGeometryMapping()),
nameof(Geometry.Centroid) => Function("ST_Centroid", new[] { instance }, typeof(Point), ResultGeometryMapping()),
nameof(GeometryCollection.Count) => Function("ST_NumGeometries", new[] { instance }, typeof(int)),
nameof(Geometry.Dimension) => Function("ST_Dimension", new[] { instance }, typeof(Dimension)),
nameof(LineString.EndPoint) => Function("ST_EndPoint", new[] { instance }, typeof(Point), resultGeometryTypeMapping),
nameof(Geometry.Envelope) => Function("ST_Envelope", new[] { instance }, typeof(Geometry), resultGeometryTypeMapping),
nameof(Polygon.ExteriorRing) => Function("ST_ExteriorRing", new[] { instance }, typeof(LineString), resultGeometryTypeMapping),
nameof(LineString.EndPoint) => Function("ST_EndPoint", new[] { instance }, typeof(Point), ResultGeometryMapping()),
nameof(Geometry.Envelope) => Function("ST_Envelope", new[] { instance }, typeof(Geometry), ResultGeometryMapping()),
nameof(Polygon.ExteriorRing) => Function("ST_ExteriorRing", new[] { instance }, typeof(LineString), ResultGeometryMapping()),
nameof(Geometry.GeometryType) => Function("GeometryType", new[] { instance }, typeof(string)),
nameof(LineString.IsClosed) => Function("ST_IsClosed", new[] { instance }, typeof(bool)),
nameof(Geometry.IsEmpty) => Function("ST_IsEmpty", new[] { instance }, typeof(bool)),
Expand All @@ -125,10 +122,10 @@ public class NpgsqlGeometryMemberTranslator : IMemberTranslator
nameof(Geometry.NumGeometries) => Function("ST_NumGeometries", new[] { instance }, typeof(int)),
nameof(Polygon.NumInteriorRings) => Function("ST_NumInteriorRings", new[] { instance }, typeof(int)),
nameof(Geometry.NumPoints) => Function("ST_NumPoints", new[] { instance }, typeof(int)),
nameof(Geometry.PointOnSurface) => Function("ST_PointOnSurface", new[] { instance }, typeof(Geometry), resultGeometryTypeMapping),
nameof(Geometry.InteriorPoint) => Function("ST_PointOnSurface", new[] { instance }, typeof(Geometry), resultGeometryTypeMapping),
nameof(Geometry.PointOnSurface) => Function("ST_PointOnSurface", new[] { instance }, typeof(Geometry), ResultGeometryMapping()),
nameof(Geometry.InteriorPoint) => Function("ST_PointOnSurface", new[] { instance }, typeof(Geometry), ResultGeometryMapping()),
nameof(Geometry.SRID) => Function("ST_SRID", new[] { instance }, typeof(int)),
nameof(LineString.StartPoint) => Function("ST_StartPoint", new[] { instance }, typeof(Point), resultGeometryTypeMapping),
nameof(LineString.StartPoint) => Function("ST_StartPoint", new[] { instance }, typeof(Point), ResultGeometryMapping()),

nameof(Geometry.OgcGeometryType) => _sqlExpressionFactory.Case(
Function("ST_GeometryType", new[] { instance }, typeof(string)),
Expand All @@ -138,10 +135,16 @@ public class NpgsqlGeometryMemberTranslator : IMemberTranslator
_ => null
};

SqlFunctionExpression Function(string name, SqlExpression[] arguments, Type returnType, RelationalTypeMapping typeMapping = null)
SqlFunctionExpression Function(string name, SqlExpression[] arguments, Type returnType, RelationalTypeMapping? typeMapping = null)
=> _sqlExpressionFactory.Function(name, arguments,
nullable: true, argumentsPropagateNullability: TrueArrays[arguments.Length],
returnType, typeMapping);

RelationalTypeMapping ResultGeometryMapping()
{
Debug.Assert(typeof(Geometry).IsAssignableFrom(returnType));
return _typeMappingSource.FindMapping(returnType, storeType)!;
}
}
}
}
Loading

0 comments on commit b6a6859

Please sign in to comment.