Skip to content

Commit

Permalink
Bump dependencies to 6.0.0-rc.2
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Oct 14, 2021
1 parent ce5604c commit f1402ee
Show file tree
Hide file tree
Showing 26 changed files with 133 additions and 403 deletions.
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<EFCoreVersion>6.0.0-rc.1.21452.10</EFCoreVersion>
<MicrosoftExtensionsVersion>6.0.0-rc.1.21451.13</MicrosoftExtensionsVersion>
<NpgsqlVersion>6.0.0-rc.2-ci.20211010T152850</NpgsqlVersion>
<EFCoreVersion>6.0.0-rc.2.21480.5</EFCoreVersion>
<MicrosoftExtensionsVersion>6.0.0-rc.2.21480.5</MicrosoftExtensionsVersion>
<NpgsqlVersion>6.0.0-rc.2</NpgsqlVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ public class NpgsqlMathTranslator : IMethodCallTranslator
{ typeof(Math).GetRuntimeMethod(nameof(Math.Tan), new[] { typeof(double) })!, "tan" },
{ typeof(MathF).GetRuntimeMethod(nameof(MathF.Tan), new[] { typeof(float) })!, "tan" },

{ typeof(Math).GetRuntimeMethod(nameof(Math.Round), new[] { typeof(double) })!, "round" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Round), new[] { typeof(decimal) })!, "round" },
{ typeof(MathF).GetRuntimeMethod(nameof(MathF.Round), new[] { typeof(float) })!, "round" },

{ typeof(Math).GetRuntimeMethod(nameof(Math.Truncate), new[] { typeof(double) })!, "trunc" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Truncate), new[] { typeof(decimal) })!, "trunc" },
{ typeof(MathF).GetRuntimeMethod(nameof(MathF.Truncate), new[] { typeof(float) })!, "trunc" },

// https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(decimal), typeof(decimal) })!, "greatest" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(double), typeof(double) })!, "greatest" },
Expand All @@ -104,6 +96,20 @@ public class NpgsqlMathTranslator : IMethodCallTranslator
{ typeof(MathF).GetRuntimeMethod(nameof(MathF.Min), new[] { typeof(float), typeof(float) })!, "least" },
};

private static readonly IEnumerable<MethodInfo> TruncateMethodInfos = new[]
{
typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Truncate), new[] { typeof(decimal) }),
typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Truncate), new[] { typeof(double) }),
typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Truncate), new[] { typeof(float) })
};

private static readonly IEnumerable<MethodInfo> RoundMethodInfos = new[]
{
typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Round), new[] { typeof(decimal) }),
typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Round), new[] { typeof(double) }),
typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Round), new[] { typeof(float) })
};

private static readonly IEnumerable<MethodInfo> SignMethodInfos = new[]
{
typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(decimal) })!,
Expand Down Expand Up @@ -181,6 +187,44 @@ public NpgsqlMathTranslator(
typeMapping);
}

if (TruncateMethodInfos.Contains(method))
{
var argument = arguments[0];
// Result of trunc for float/double is always double in server side
var result = (SqlExpression)_sqlExpressionFactory.Function(
"trunc",
new[] { argument },
nullable: true,
argumentsPropagateNullability: new[] { true, false, false },
typeof(double));

if (argument.Type == typeof(float))
{
result = _sqlExpressionFactory.Convert(result, typeof(float));
}

return _sqlExpressionFactory.ApplyTypeMapping(result, argument.TypeMapping);
}

if (RoundMethodInfos.Contains(method))
{
var argument = arguments[0];
// Result of round for float/double is always double in server side
var result = (SqlExpression) _sqlExpressionFactory.Function(
"round",
new[] { argument },
nullable: true,
argumentsPropagateNullability: new[] { true, true },
typeof(double));

if (argument.Type == typeof(float))
{
result = _sqlExpressionFactory.Convert(result, typeof(float));
}

return _sqlExpressionFactory.ApplyTypeMapping(result, argument.TypeMapping);
}

// PostgreSQL sign() returns 1, 0, -1, but in the same type as the argument, so we need to convert
// the return type to int.
if (SignMethodInfos.Contains(method))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping
/// </remarks>
public class NpgsqlEStringTypeMapping : StringTypeMapping
{
public NpgsqlEStringTypeMapping() : base("does_not_exist") {}
public NpgsqlEStringTypeMapping() : base("does_not_exist", System.Data.DbType.String) {}

protected override string GenerateNonNullSqlLiteral(object value)
=> $"E'{EscapeSqlLiteral((string)value)}'";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Data.Common;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NpgsqlTypes;

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping
Expand All @@ -22,7 +21,7 @@ public class NpgsqlStringTypeMapping : StringTypeMapping, INpgsqlTypeMapping
/// <param name="storeType">The database type to map.</param>
/// <param name="npgsqlDbType">The database type used by Npgsql.</param>
public NpgsqlStringTypeMapping(string storeType, NpgsqlDbType npgsqlDbType)
: base(storeType)
: base(storeType, System.Data.DbType.String)
=> NpgsqlDbType = npgsqlDbType;

protected NpgsqlStringTypeMapping(
Expand Down
5 changes: 2 additions & 3 deletions src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ await Dependencies.MigrationCommandExecutor
}

public override bool HasTables()
=> Dependencies.ExecutionStrategyFactory
.Create()
=> Dependencies.ExecutionStrategy
.Execute(
_connection,
connection => (bool)CreateHasTablesCommand()
Expand All @@ -97,7 +96,7 @@ public override bool HasTables()
Dependencies.CommandLogger))!);

public override Task<bool> HasTablesAsync(CancellationToken cancellationToken = default)
=> Dependencies.ExecutionStrategyFactory.Create().ExecuteAsync(
=> Dependencies.ExecutionStrategy.ExecuteAsync(
_connection,
async (connection, ct) => (bool)(await CreateHasTablesCommand()
.ExecuteScalarAsync(
Expand Down
51 changes: 1 addition & 50 deletions test/EFCore.PG.FunctionalTests/DataAnnotationNpgsqlTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -19,56 +20,6 @@ public DataAnnotationNpgsqlTest(DataAnnotationNpgsqlFixture fixture)
protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction)
=> facade.UseTransaction(transaction.GetDbTransaction());

// Need to override some tests because the base class defines their string properties with type
// nvarchar(128) which is SQL Server-specific
[Fact]
public override ModelBuilder Field_annotations_are_enabled()
{
var modelBuilder = CreateModelBuilder();

modelBuilder.Entity<FieldAnnotationClass>()
.Property<string>("_personFirstName")
.HasColumnType("varchar(128)");

Validate(modelBuilder);

Assert.True(GetProperty<FieldAnnotationClass>(modelBuilder, "_personFirstName").IsPrimaryKey());

return modelBuilder;
}

[Fact]
public override ModelBuilder Non_public_annotations_are_enabled()
{
var modelBuilder = CreateModelBuilder();

modelBuilder.Entity<PrivateMemberAnnotationClass>().Property(
PrivateMemberAnnotationClass.PersonFirstNameExpr)
.HasColumnType("varchar(128)");

Validate(modelBuilder);

Assert.True(GetProperty<PrivateMemberAnnotationClass>(modelBuilder, "PersonFirstName").IsPrimaryKey());

return modelBuilder;
}

[Fact]
public override ModelBuilder Key_and_column_work_together()
{
var modelBuilder = CreateModelBuilder();

modelBuilder.Entity<ColumnKeyAnnotationClass1>()
.Property(c => c.PersonFirstName)
.HasColumnType("varchar(128)");

Validate(modelBuilder);

Assert.True(GetProperty<ColumnKeyAnnotationClass1>(modelBuilder, "PersonFirstName").IsPrimaryKey());

return modelBuilder;
}

public override void StringLengthAttribute_throws_while_inserting_value_longer_than_max_length()
{
// Npgsql does not support length
Expand Down
143 changes: 0 additions & 143 deletions test/EFCore.PG.FunctionalTests/GraphUpdates/GraphUpdatesNpgsqlTest.cs

This file was deleted.

Loading

0 comments on commit f1402ee

Please sign in to comment.