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

Sequence contains no elements running in-memory query with class key #26238

Closed
ajcvickers opened this issue Oct 3, 2021 · 2 comments
Closed
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. type-bug

Comments

@ajcvickers
Copy link
Member

See skipped tests in KeysWithConvertersInMemoryTest

@ajcvickers ajcvickers changed the title In-memory database does not compare keys using specified key comparer Sequence contains no elements running In-memory query with class key Oct 6, 2021
@ajcvickers
Copy link
Member Author

Example of test that fails:

        [ConditionalFact]
        public virtual void Can_query_and_update_owned_entity_with_int_bare_class_key()
        {
            using (var context = CreateContext())
            {
                context.Add(new OwnerBareIntClassKey(new(1), new(77)));
                context.SaveChanges();
            }

            using (var context = CreateContext())
            {
                var owner = context.Set<OwnerBareIntClassKey>().Single(o => o.Id.Equals(new BareIntClassKey(1)));
                Assert.Equal(77, owner.Owned.Position);

                owner.Owned = new(88);
                context.SaveChanges();
            }

            using (var context = CreateContext())
            {
                var owner = context.Set<OwnerBareIntClassKey>().Find(new BareIntClassKey(1));
                Assert.Equal(88, owner.Owned.Position);
            }
        }

Exception thrown:

System.InvalidOperationException
Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at lambda_method140(Closure )
   at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryQueryExpression.ResultEnumerable.GetEnumerator() in C:\dotnet\efcore\src\EFCore.InMemory\Query\Internal\InMemoryQueryExpression.Helper.cs:line 28
   at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable`1.Enumerator.MoveNextHelper() in C:\dotnet\efcore\src\EFCore.InMemory\Query\Internal\InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs:line 153
   at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable`1.Enumerator.MoveNext() in C:\dotnet\efcore\src\EFCore.InMemory\Query\Internal\InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs:line 107
   at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Boolean& found)
   at lambda_method139(Closure , QueryContext )
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) in C:\dotnet\efcore\src\EFCore\Query\Internal\QueryCompiler.cs:line 97
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) in C:\dotnet\efcore\src\EFCore\Query\Internal\EntityQueryProvider.cs:line 78
   at System.Linq.Queryable.Single[TSource](IQueryable`1 source, Expression`1 predicate)
   at Microsoft.EntityFrameworkCore.KeysWithConvertersTestBase`1.Can_query_and_update_owned_entity_with_int_bare_class_key() in C:\dotnet\efcore\test\EFCore.Specification.Tests\KeysWithConvertersTestBase.cs:line 2223
   at Microsoft.EntityFrameworkCore.KeysWithConvertersInMemoryTest.Can_query_and_update_owned_entity_with_int_bare_class_key() in C:\dotnet\efcore\test\EFCore.InMemory.FunctionalTests\KeysWithConvertersInMemoryTest.cs:line 50

Types used:

protected class OwnerBareIntClassKey
{
    public OwnerBareIntClassKey(BareIntClassKey id)
    {
        Id = id;
    }

    public OwnerBareIntClassKey(BareIntClassKey id, OwnedBareIntClassKey owned)
    {
        Id = id;
        Owned = owned;
    }

    public BareIntClassKey Id { get; set; }
    public OwnedBareIntClassKey Owned { get; set; }
}

protected class OwnedBareIntClassKey
{
    public OwnedBareIntClassKey(int position)
    {
        Position = position;
    }
    
    public int Position { get; set; }
}

protected class BareIntClassKey
{
    public static ValueConverter<BareIntClassKey, int> Converter
        = new(v => v.Id, v => new BareIntClassKey(v));

    public static ValueComparer<BareIntClassKey> Comparer
        = new ValueComparer<BareIntClassKey>(
            (l, r) => l.Id == r.Id,
            v => v.Id.GetHashCode(),
            v => new(v.Id));
    
    public BareIntClassKey(int id)
    {
        Id = id;
    }

    public int Id { get; set; }
}

@ajcvickers ajcvickers added this to the Backlog milestone Oct 6, 2021
@ajcvickers ajcvickers changed the title Sequence contains no elements running In-memory query with class key Sequence contains no elements running in-memory query with class key Oct 6, 2021
@smitpatel smitpatel self-assigned this Oct 6, 2021
@ajcvickers ajcvickers modified the milestones: Backlog, 7.0.0 Nov 10, 2021
@ajcvickers ajcvickers added punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. and removed propose-punt labels Jul 7, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, Backlog Jul 7, 2022
@smitpatel smitpatel removed their assignment Sep 14, 2022
@ajcvickers
Copy link
Member Author

We recommend against using the in-memory provider for testing--see Testing EF Core Applications. While we have no plans to remove the in-memory provider, we will not be adding any new features to this provider because we believe valuable development time is better spent in other areas. When feasible, we plan to still fix regressions in existing behavior.

@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2022
@ajcvickers ajcvickers added closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. and removed propose-close area-query area-in-memory punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. labels Oct 26, 2022
@ajcvickers ajcvickers removed this from the Backlog milestone Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. type-bug
Projects
None yet
Development

No branches or pull requests

2 participants