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

NullReferenceException when materialing object with AsNoTracking() in EF 6.3.0 and higher #1814

Closed
jonnybee opened this issue Feb 17, 2021 · 3 comments

Comments

@jonnybee
Copy link

This could be a tricky one and may be located in Oracle.ManagedDataAccesss.EntityFramework

I've been digging into this issue this weekend and it surfaced by a this change in commit 2483303 "Query compilation performance" #430:

    private const int MaxNodeCountForTransformations = 100000;   // from 
    private const int MaxNodeCountForTransformations = 10000;     // to 

For my app I could workaround by adding this switch to the web.config/app.config

<configuration>  
    <system.diagnostics>  
         <switches>  
                 <add name="System.Data.Entity.Core.EntityClient.IgnoreOptimizationLimit" value="1"/>  
         </switches>  
    </system.diagnostics>  
 </configuration> 

When you have large queries that hit this threshold in the PlanOptimizer (+370 columns and a number of tables, my query has nodecount=16885) the ObjectStateManager.AddEntityToCollectionOrReference may get a NullEntityWrapper in wrappedTarget parameter and this blows up in a NullReferenceException in GetOtherEndOfRelationship:

    internal RelatedEnd GetOtherEndOfRelationship(IEntityWrapper wrappedEntity)
    {
        DebugCheck.NotNull(wrappedEntity);
        EnsureRelationshipNavigationAccessorsInitialized();
        return wrappedEntity.RelationshipManager.GetRelatedEnd(_navigation.Reverse, _relationshipFixer);
    }

where a NullEntityWrapper returns

    public RelationshipManager RelationshipManager
    {
        get
        {
            Debug.Fail("Cannot access RelationshipManager from null wrapper.");
            return null;
        }
    }

When materializing objects in Shaper.MaterializeRow() the Coordinator for one (and only one) of the child collections in the Include(...) returns a NullEntityWrapper.

We have only seen this Exception when running EF Queries with AsNoTracking() against Oracle DB in our app, running the same queries without AsNoTracking() does not throw exception. And against SqlServer both with and without AsNoTracking() is working fine.

So is this most likely a bug in the Oracle.ManagedDataAccess.EntityFramework provider or a bug in EF 6 itself?

@efeblesp for notification.

Originally posted by @jonnybee in #1408 (comment)

@jonnybee
Copy link
Author

Sorry, closing this issue. I cannot reproduce this exception now with latest versions of EF 6 and Oracle provider.

@efeblesp
Copy link

Hi @jonnybee , what version of EF and Oracle you used that worked? Did you try with the same query that previously failed with older version of EF?

@jonnybee
Copy link
Author

jonnybee commented Feb 18, 2021

I used the same Query that previously failed with EF 6.4.4, Oracle.ManagedDataAccess v 19.10.0 and Oracle.ManagedDataAccess.EntityFramework v 19.7.0 and it was working fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants