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

InMemory: FirstOrDefault is not working #16825

Closed
razfriman opened this issue Jul 29, 2019 · 4 comments
Closed

InMemory: FirstOrDefault is not working #16825

razfriman opened this issue Jul 29, 2019 · 4 comments
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@razfriman
Copy link

razfriman commented Jul 29, 2019

FirstOrDefault linq on queries (InMemory) is still not working in preview 7.

I assumed since preview-7 was released this would be fixed. If not, is there anywhere that this is being tracked?

If you are seeing an exception, include the full exceptions details (message and stack trace).

Exception message:  System.NullReferenceException: Object reference not set to an instance of an object.
Stack trace:
System.NullReferenceException: Object reference not set to an instance of an object.
    at lambda_method(Closure , QueryContext , ValueBuffer )
    at Microsoft.EntityFrameworkCore.InMemory.Query.Pipeline.InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable`1.Enumerator.MoveNext()
    at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
    at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
    at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
    at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
    at RazzleServer.Login.Maple.LoginAccount.Load() in /Users/razfriman/CODE/razzle-server/RazzleServer.Login/Maple/LoginAccount.cs:line 21

Steps to reproduce

Include a complete code listing (or project/solution) that we can run to reproduce the issue.

Created a branch in my open project for reproducing the issue, also extracted out the single passing/failing test for simplicity.

https://github.com/razfriman/RazzleServer/blob/raz/update-7/RazzleServer.Tests/LoginClientIntegrationTest.cs#L25

        [TestMethod] // Fails
        public void testFirstOrDefault()
        {
            using var dbContext = new MapleDbContext();
            var account = dbContext.Accounts.FirstOrDefault(x => x.Username == "abc");

        }
        
        [TestMethod] // Passes
        public void testFirstOrDefaultAfterMaterializing()
        {
            using var dbContext = new MapleDbContext();
            var account = dbContext.Accounts.ToList().FirstOrDefault(x => x.Username == "abc");

        }

Further technical details

.NET Core version: preview 7
EF Core version: (found in project.csproj or packages.config)
Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0-preview7.19362.6" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.0.0-preview7.19362.6" />
        <PackageReference Include="System.ComponentModel.Annotations" Version="4.6.0-preview7.19362.9" />

Operating system: Mac OSX 10.14.5
IDE: (e.g. Visual Studio 2017 15.4) .NET Core CLI

@smitpatel
Copy link
Contributor

This should be fixed in nightlies.

@smitpatel smitpatel changed the title InMemory: FirstOrDefault incorrectly translated to SingleOrDefault InMemory: FirstOrDefault is not working Jul 30, 2019
@smitpatel
Copy link
Contributor

SingleOrDefault is implementation detail and not the translation.

@Euphoric
Copy link

Euphoric commented Aug 2, 2019

@smitpatel Hi. Can you link to the PR that fixes this?

@ajcvickers
Copy link
Member

Verified fixed with nightlies.

@Euphoric There are many PRs that have contributed to this, but I suspect #16576 is the main one for this specific issue.

@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 2, 2019
@ajcvickers ajcvickers added this to the 3.0.0-preview8 milestone Aug 2, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0-preview8, 3.0.0 Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

No branches or pull requests

4 participants