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

Query: Add regression test for #25680 #25709

Merged
merged 1 commit into from
Aug 25, 2021
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -23,13 +24,14 @@ protected TestSqlLoggerFactory TestSqlLoggerFactory
public virtual async Task Multiple_owned_reference_mapped_to_own_table_containing_owned_collection_in_split_query(bool async)
{
var contextFactory = await InitializeAsync<Context24777>();
using var context = contextFactory.CreateContext();

using (var context = contextFactory.CreateContext())
{
var root3 = await context.Roots.Where(e => e.Id == 3).AsSplitQuery().SingleAsync();
var query = context.Roots.Where(e => e.Id == 3).AsSplitQuery();
var root3 = async
? await query.SingleAsync()
: query.Single();

Assert.Equal(2, root3.ModdleA.Leaves.Count);
}
Assert.Equal(2, root3.ModdleA.Leaves.Count);
}

protected class Context24777 : DbContext
Expand Down Expand Up @@ -113,5 +115,54 @@ protected class Leaf24777
public int ModdleAId { get; init; }
public int UnitThreshold { get; init; }
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Owned_collection_basic_split_query(bool async)
{
var contextFactory = await InitializeAsync<Context25680>();
using var context = contextFactory.CreateContext();

var id = new Guid("6c1ae3e5-30b9-4c77-8d98-f02075974a0a");
var query = context.Set<Location25680>().Where(e => e.Id == id).AsSplitQuery();
var result = async
? await query.FirstOrDefaultAsync()
: query.FirstOrDefault();
}

protected class Context25680 : DbContext
{
public Context25680(DbContextOptions options)
: base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Location25680>().OwnsMany(e => e.PublishTokenTypes,
b =>
{
b.WithOwner(e => e.Location).HasForeignKey(e => e.LocationId);
b.HasKey(e => new { e.LocationId, e.ExternalId, e.VisualNumber, e.TokenGroupId });
});
}
}

protected class Location25680
{
public Guid Id { get; set; }
public ICollection<PublishTokenType25680> PublishTokenTypes { get; set; }
}

protected class PublishTokenType25680
{
public Location25680 Location { get; set; }
public Guid LocationId { get; set; }

public string ExternalId { get; set; }
public string VisualNumber { get; set; }
public string TokenGroupId { get; set; }
public string IssuerName { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,18 @@ FROM [Warehouses] AS [w]
LEFT JOIN [WarehouseDestinationCountry] AS [w0] ON [w].[WarehouseCode] = [w0].[WarehouseCode]
ORDER BY [w].[Id], [w0].[WarehouseCode]");
}

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

AssertSql(
@"@__id_0='6c1ae3e5-30b9-4c77-8d98-f02075974a0a'

SELECT TOP(1) [l].[Id]
FROM [Location25680] AS [l]
WHERE [l].[Id] = @__id_0
ORDER BY [l].[Id]");
}
}
}