Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>11.0.0-rc.3</VersionPrefix>
<VersionPrefix>11.0.0</VersionPrefix>
<TargetFramework>net11.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
Expand Down
16 changes: 8 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<EFCoreVersion>11.0.0-rc.3.26522.148</EFCoreVersion>
<MicrosoftExtensionsVersion>11.0.0-rc.3.26522.148</MicrosoftExtensionsVersion>
<MicrosoftExtensionsConfigurationVersion>11.0.0-rc.3.26522.148</MicrosoftExtensionsConfigurationVersion>
<EFCoreVersion>11.0.0</EFCoreVersion>
<MicrosoftExtensionsVersion>11.0.0</MicrosoftExtensionsVersion>
<MicrosoftExtensionsConfigurationVersion>11.0.0</MicrosoftExtensionsConfigurationVersion>
<NpgsqlVersion>10.0.3</NpgsqlVersion>
<XunitVersion>4.0.1</XunitVersion>
</PropertyGroup>
Expand All @@ -12,11 +12,11 @@
Dependencies on EF preview versions should be locked to a specific version (as provider-facing breaking changes are frequent).
For released versions, depend on anything in the current major version to allow users to update to higher patch versions.
-->
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="[$(EFCoreVersion)]" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="[$(EFCoreVersion)]" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Abstractions" Version="[$(EFCoreVersion)]" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="[$(EFCoreVersion)]" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="[$(EFCoreVersion)]" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="[$(EFCoreVersion),12.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="[$(EFCoreVersion),12.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Abstractions" Version="[$(EFCoreVersion),12.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="[$(EFCoreVersion),12.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="[$(EFCoreVersion),12.0.0)" />

<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsConfigurationVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsConfigurationVersion)" />
Expand Down
3 changes: 1 addition & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"sdk": {
"version": "11.0.100-rc.3.26522.148",
"allowPrerelease": true
"version": "11.0.100"
},
"test": {
"runner": "Microsoft.Testing.Platform"
Expand Down
10 changes: 3 additions & 7 deletions src/EFCore.PG/Metadata/Internal/NpgsqlAnnotationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,10 @@ public override IEnumerable<IAnnotation> For(ITableIndex index, bool designTime)

foreach (var annotation in base.For(index, designTime))
{
// TODO: Remove the whole-document exclusion after consuming https://github.com/dotnet/efcore/pull/39089.
// EF 11 RC2 cannot scaffold Relational:JsonIndex; excluding it preserves existing whole-document scaffolding.
if (annotation.Value is RelationalJsonIndex jsonIndex
&& (jsonIndex.Elements.Any(e => e.Path.Count > 0)
|| jsonIndex.CollectionIndices?.Any(indices => indices?.Any(i => i.HasValue) == true) == true))
{
yield return annotation;
yield return annotation;

if (annotation.Value is RelationalJsonIndex jsonIndex)
{
// JSON paths alone don't capture changes to the casts used by PostgreSQL expression indexes.
yield return new Annotation(
NpgsqlAnnotationNames.JsonIndexTypes,
Expand Down
10 changes: 6 additions & 4 deletions src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2507,7 +2507,7 @@ private static bool TryParseSchema(string identifier, out string name, out strin

/// <summary>
/// Builds index keys using facets from <paramref name="operation"/>. When supplied, <paramref name="jsonIndex"/>
/// defines the keys and extraction expressions instead of the operation's deduplicated container columns.
/// defines the keys, extraction expressions and sort directions instead of the operation's deduplicated container columns.
/// </summary>
private IndexColumn[] GetIndexColumns(CreateIndexOperation operation, RelationalJsonIndex? jsonIndex)
{
Expand All @@ -2528,9 +2528,11 @@ private IndexColumn[] GetIndexColumns(CreateIndexOperation operation, Relational
var name = jsonIndex?.Elements[i].ContainingColumn.Name ?? operation.Columns[i];
var @operator = i < operators?.Length ? operators[i] : null;
var collation = i < collations?.Length ? collations[i] : null;
var isColumnDescending = isDescendingValues is not null
? isDescendingValues.Length == 0 || isDescendingValues[i]
: i < legacySortOrders?.Length && legacySortOrders[i] == SortOrder.Descending;
var isColumnDescending = jsonIndex is not null
? jsonIndex.IsElementDescending(i)
: isDescendingValues is not null
? isDescendingValues.Length == 0 || isDescendingValues[i]
: i < legacySortOrders?.Length && legacySortOrders[i] == SortOrder.Descending;
var nullSortOrder = i < nullSortOrders?.Length ? nullSortOrders[i] : NullSortOrder.Unspecified;

columns[i] = new IndexColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,65 +47,6 @@ protected override Expression VisitExtension(Expression extensionExpression)
? array
: base.VisitExtension(extensionExpression);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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>
protected override Expression VisitConditional(ConditionalExpression conditionalExpression)
{
var test = Visit(conditionalExpression.Test);
var ifTrue = Visit(conditionalExpression.IfTrue);
var ifFalse = Visit(conditionalExpression.IfFalse);

if (TranslationFailed(conditionalExpression.Test, test, out var sqlTest)
|| TranslationFailed(conditionalExpression.IfTrue, ifTrue, out var sqlIfTrue)
|| TranslationFailed(conditionalExpression.IfFalse, ifFalse, out var sqlIfFalse))
{
return QueryCompilationContext.NotTranslatedExpression;
}

// Translate:
// a == b ? null : a -> NULLIF(a, b)
// a != b ? a : null -> NULLIF(a, b)
if (sqlTest is SqlBinaryExpression binary && sqlIfTrue is not null && sqlIfFalse is not null)
{
switch (binary.OperatorType)
{
case ExpressionType.Equal
when ifTrue is SqlConstantExpression { Value: null } && TryTranslateToNullIf(sqlIfFalse, out var nullIfTranslation):
case ExpressionType.NotEqual
when ifFalse is SqlConstantExpression { Value: null } && TryTranslateToNullIf(sqlIfTrue, out nullIfTranslation):
return nullIfTranslation;
}
}

return _sqlExpressionFactory.Case([new CaseWhenClause(sqlTest!, sqlIfTrue!)], sqlIfFalse);

bool TryTranslateToNullIf(SqlExpression conditionalResult, [NotNullWhen(true)] out Expression? nullIfTranslation)
{
var (left, right) = (binary.Left, binary.Right);

if (left.Equals(conditionalResult))
{
nullIfTranslation = _sqlExpressionFactory.Function(
"NULLIF", [left, right], true, [false, false], left.Type, left.TypeMapping);
return true;
}

if (right.Equals(conditionalResult))
{
nullIfTranslation = _sqlExpressionFactory.Function(
"NULLIF", [right, left], true, [false, false], right.Type, right.TypeMapping);
return true;
}

nullIfTranslation = null;
return false;
}
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,7 @@ public void Create_json_member_composite_index(bool descending)
{
Name = "IX_Json",
Table = "Blogs",
Columns = ["Details"],
IsDescending = descending ? [] : null
Columns = ["Details"]
});

var direction = descending ? " DESC" : "";
Expand All @@ -911,15 +910,14 @@ public void Create_json_member_index_with_options()
b =>
{
BuildJsonIndexModel(b);
b.Entity<JsonIndexBlog>().HasIndex(e => e.Details.Slug).HasDatabaseName("IX_Json");
b.Entity<JsonIndexBlog>().HasIndex(e => e.Details.Slug).HasDatabaseName("IX_Json").IsDescending();
},
new CreateIndexOperation
{
Name = "IX_Json",
Table = "Blogs",
Columns = ["Details"],
IsUnique = true,
IsDescending = [true],
Filter = "\"Id\" > 0",
[NpgsqlAnnotationNames.CreatedConcurrently] = true,
[NpgsqlAnnotationNames.IndexOperators] = new[] { "text_ops" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,31 @@ public override async Task Where_HasValue_on_nullable_value_type()

#endregion Value types

// https://github.com/dotnet/efcore/issues/34627
public override async Task FromSql_on_root()
{
await Assert.ThrowsAnyAsync<Exception>(base.FromSql_on_root);
await base.FromSql_on_root();

AssertSql();
AssertSql(
"""
SELECT m."Id", m."Name", m."AssociateCollection", m."OptionalAssociate", m."RequiredAssociate"
FROM (
SELECT * FROM "RootEntity"
) AS m
""");
}

public override async Task FromSql_on_root_composed(bool async)
{
await base.FromSql_on_root_composed(async);

AssertSql(
"""
SELECT m."Id", m."Name", m."AssociateCollection", m."OptionalAssociate", m."RequiredAssociate"
FROM (
SELECT * FROM "RootEntity"
) AS m
WHERE (CAST(m."RequiredAssociate" ->> 'Int' AS integer)) = 8
""");
}

[ConditionalFact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,100 @@ public override Task Delete_required_associate()
public override Task Delete_optional_associate()
=> Assert.ThrowsAsync<PostgresException>(base.Delete_optional_associate);

// PostgreSQL generates valid SQL for these but produces wrong row counts due to self-joins in UPDATE ... FROM
public override Task Update_property_inside_associate()
=> Assert.ThrowsAsync<EqualException>(base.Update_property_inside_associate);
public override async Task Update_property_inside_associate()
{
await base.Update_property_inside_associate();

AssertExecuteUpdateSql(
"""
@p='foo_updated'
UPDATE "AssociateType" AS a
SET "String" = @p
FROM "RootEntity" AS r
WHERE r."RequiredAssociateId" = a."Id"
""");
}

public override async Task Update_property_inside_associate_with_special_chars()
{
await base.Update_property_inside_associate_with_special_chars();

AssertExecuteUpdateSql(
"""
UPDATE "AssociateType" AS a0
SET "String" = '{ Some other/JSON:like text though it [isn''t]: ממש ממש לאéèéè }'
FROM "RootEntity" AS r
INNER JOIN "AssociateType" AS a ON r."RequiredAssociateId" = a."Id"
WHERE r."RequiredAssociateId" = a0."Id" AND a."String" = '{ this may/look:like JSON but it [isn''t]: ממש ממש לאéèéè }'
""");
}

public override Task Update_property_inside_associate_with_special_chars()
=> Assert.ThrowsAsync<EqualException>(base.Update_property_inside_associate_with_special_chars);
public override async Task Update_property_on_projected_associate()
{
await base.Update_property_on_projected_associate();

public override Task Update_property_on_projected_associate()
=> Assert.ThrowsAsync<EqualException>(base.Update_property_on_projected_associate);
AssertExecuteUpdateSql(
"""
@p='foo_updated'
UPDATE "AssociateType" AS a
SET "String" = @p
FROM "RootEntity" AS r
WHERE r."RequiredAssociateId" = a."Id"
""");
}

// PostgreSQL produces wrong row counts due to self-joins in UPDATE ... FROM.
public override Task Update_property_on_projected_associate_with_OrderBy_Skip()
=> Assert.ThrowsAsync<EqualException>(base.Update_property_on_projected_associate_with_OrderBy_Skip);

public override Task Update_multiple_properties_inside_same_associate()
=> Assert.ThrowsAsync<EqualException>(base.Update_multiple_properties_inside_same_associate);
public override async Task Update_multiple_properties_inside_same_associate()
{
await base.Update_multiple_properties_inside_same_associate();

AssertExecuteUpdateSql(
"""
@p='foo_updated'
@p1='20'
UPDATE "AssociateType" AS a
SET "String" = @p,
"Int" = @p1
FROM "RootEntity" AS r
WHERE r."RequiredAssociateId" = a."Id"
""");
}

public override async Task Update_primitive_collection_to_constant()
{
await base.Update_primitive_collection_to_constant();

AssertExecuteUpdateSql(
"""
UPDATE "AssociateType" AS a
SET "Ints" = ARRAY[1,2,4]::integer[]
FROM "RootEntity" AS r
WHERE r."RequiredAssociateId" = a."Id"
""");
}

public override Task Update_primitive_collection_to_constant()
=> Assert.ThrowsAsync<EqualException>(base.Update_primitive_collection_to_constant);
public override async Task Update_primitive_collection_to_parameter()
{
await base.Update_primitive_collection_to_parameter();

public override Task Update_primitive_collection_to_parameter()
=> Assert.ThrowsAsync<EqualException>(base.Update_primitive_collection_to_parameter);
AssertExecuteUpdateSql(
"""
@ints={ '1'
'2'
'4' } (DbType = Object)
UPDATE "AssociateType" AS a
SET "Ints" = @ints
FROM "RootEntity" AS r
WHERE r."RequiredAssociateId" = a."Id"
""");
}

// Translation not yet supported for navigation-mapped associations
public override Task Update_associate_to_parameter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1394,10 +1394,10 @@ public override async Task Select_TPC_base_with_ComplexType()

AssertSql(
"""
SELECT t."Id", t."ChildProperty", NULL AS "ChildProperty1", t."PropertyInsideComplexThing", t."ChildComplexProperty_PropertyInsideComplexThing", NULL AS "ChildComplexProperty_PropertyInsideComplexThing1", 'TpcChild1' AS "Discriminator"
SELECT t."Id", t."ChildProperty", NULL AS "ChildProperty1", t."BaseComplexProperty_PropertyInsideComplexThing", t."ChildComplexProperty_PropertyInsideComplexThing", NULL AS "ChildComplexProperty_PropertyInsideComplexThing1", 'TpcChild1' AS "Discriminator"
FROM "TpcChild1" AS t
UNION ALL
SELECT t0."Id", NULL AS "ChildProperty", t0."ChildProperty" AS "ChildProperty1", t0."PropertyInsideComplexThing", NULL AS "ChildComplexProperty_PropertyInsideComplexThing", t0."ChildComplexProperty_PropertyInsideComplexThing" AS "ChildComplexProperty_PropertyInsideComplexThing1", 'TpcChild2' AS "Discriminator"
SELECT t0."Id", NULL AS "ChildProperty", t0."ChildProperty" AS "ChildProperty1", t0."BaseComplexProperty_PropertyInsideComplexThing", NULL AS "ChildComplexProperty_PropertyInsideComplexThing", t0."ChildComplexProperty_PropertyInsideComplexThing" AS "ChildComplexProperty_PropertyInsideComplexThing1", 'TpcChild2' AS "Discriminator"
FROM "TpcChild2" AS t0
""");
}
Expand Down
Loading
Loading