question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Reposiories Get*WithInclude() where related enitities are eagerly loaded

See original GitHub issue

In relation to #157 I nice feature would be to have built in support for *eager loading of child entities. While it is understood that the current limitation is that this is not supported by NHibernate implementing this would be a nice addition. eg:

        /// <summary>
        ///     Same behaviour as Get() but also eagerly loads any included entities
        /// </summary>
        /// <param name="aKey">Primary key</param>
        /// <returns>Record if found, NullException otherwise</returns>
        public StructureDivisionEntity GetWithInclude(long aKey)
        {
            return GetAllWithInclude()
                .Include(e => e.Structure)
                .Include(e => e.ParentStructureDivision.Structure)
                .First(r => r.Id == aKey);
        }

        /// <summary>
        ///     Same behaviour as GetAll() but also eagerly loads any included entities
        /// </summary>
        /// <returns>Records if found, empty list otherwise</returns>

        public IQueryable<StructureDivisionEntity> GetAllWithInclude()
        {
            return GetAllWithInclude()
                .Include(e => e.Structure)
                .Include(e => e.ParentStructureDivision.Structure);
        }

The implementation above could be improved by doing a dynamic scan of referenced entities and providing the depth of recursion for referenced entities

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hikalkancommented, Oct 17, 2014

Hi,

You can add reference of EF to your application layer. Then call _repository.GetAll().Include(…)

You can say that: “Depending EF is not right on app layer” but when we add Include to repository, you will be depend on EF either. So, I think no problem to add it unless you don’t change EF in the future. In this way, you can also use Async LinQ entensions.

0reactions
zhaoqinglongcommented, Jul 4, 2017

thanks,i used this property in my project today

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eager Loading of Related Data - EF Core
Entity Framework Core will automatically fix-up navigation properties to any other entities that were previously loaded into the context ...
Read more >
Entity Framework Core Repository Pattern Eager Load
In my repository, I have an interface similar to this. Using DBSet, I am able to use the Find method to generically find...
Read more >
Eager Loading In Repository Pattern Entity Framework Core
The method EntityWithEagerLoad() takes 2 arguments, one is filter criteria and another is an array of entities which we want to eager load....
Read more >
Eager Loading in Entity Framework
Eager loading is the process whereby a query for one type of entity also loads related entities as part of the query, so...
Read more >
Generic Entity Framework Repository with Eager Loading
In this post am going to explain how we can write Generic repository for Entity framework. The implementation is based on the Repository...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found