Coder Social home page Coder Social logo

Comments (5)

crhairr avatar crhairr commented on June 1, 2024

Try using Include(character => character.Account).

from entityframeworkcore.

LoghamLogan avatar LoghamLogan commented on June 1, 2024

Ah sorry, I did not realize that lazy loading is not yet implemented in EFCore yet!
Unfortunately, no luck using Include(character => character.Account) either.
Do I need to enable an option when configuring my context?

Looks like the model it's generating is correct:

Model: 
  EntityType: AccountData
    Properties: 
      Id (Guid) Required PK AfterSave:Throw ValueGenerated.OnAdd 0 0 0 -1 0
      EmbededList (ICollection<UserItem>) 1 1 -1 -1 -1
      Username (string) 2 2 -1 -1 -1
    Keys: 
      Id PK
    Annotations: 
      RelationshipDiscoveryConvention:NavigationCandidates: System.Collections.Immutable.ImmutableSortedDictionary`2[System.Reflection.PropertyInfo,System.Type]
  EntityType: CharacterData
    Properties: 
      Id (Guid) Required PK AfterSave:Throw ValueGenerated.OnAdd 0 0 0 -1 0
      AccountId (no field, Nullable<Guid>) Shadow FK Index 1 1 1 0 1
      Name (string) 2 2 -1 -1 -1
    Navigations: 
      Account (<Account>k__BackingField, AccountData) ToPrincipal AccountData 0 -1 2 -1 -1
    Keys: 
      Id PK
    Foreign keys: 
      CharacterData {'AccountId'} -> AccountData {'Id'} ToPrincipal: Account
    Annotations: 
      RelationshipDiscoveryConvention:NavigationCandidates: System.Collections.Immutable.ImmutableSortedDictionary`2[System.Reflection.PropertyInfo,System.Type]
Annotations: 
  MongoDb:Database: testdb
  ProductVersion: 2.1.0-preview1-27567

from entityframeworkcore.

crhairr avatar crhairr commented on June 1, 2024

I apologize for the delay: I was out of town over the weekend for the holiday. I'll be looking into this issue tonight when I get back to my personal PC.

In the meantime, take a look at this unit test. See if there are any obvious differences between your data model and how I've set up the sample domain, as well as the use of the Include in the test.

from entityframeworkcore.

crhairr avatar crhairr commented on June 1, 2024

This should now be fixed. I was passing off my queries to the EF Core library for compilation, and it was making some assumptions about the underlying query provider that weren't holding up. Essentially, Includes get compiled to either Joins or GroupJoins with a transparent identifier, which EF Core executes client-side and then uses a projection to fix up the navigations. The metadata for EFCore-MongoDB didn't match what EF Core was expecting, so it was failing to fix up the navigations when processing the transparent identifiers. I had to completely rewrite the query compilation code for navigations in order to work around this, but it's now correctly using the $lookup operator.

Unfortunately, the current MongoDB C# driver does not yet have support for the $addFields or $mergeObjects pipeline operators (MongoDB 3.6+), so my code still has to use a transparent identifier and fix up the navigations once the results come back. This might cause unexpected behaviors in more complex queries (such as Including several layers of navigations, or including a navigation from a collection member, etc.) due to how the queries have to be rewritten in order for the transparent identifier to work. I have to explore these and make sure that the code handles them correctly, but for now simple navigation queries should load correctly.

This single Include test and this enumerable include test show navigations being loaded in a query, for reference.

Please give the latest preview build a try and let me know if you see any more issues.

from entityframeworkcore.

crhairr avatar crhairr commented on June 1, 2024

Tests are working: relationships are fully hydrated when using Include.

from entityframeworkcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.