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

Entity Framework can't load related entities when use Query().Load() for many to many relation #589

Closed
NikolayYeryomenko opened this issue Aug 7, 2018 · 1 comment

Comments

@NikolayYeryomenko
Copy link

NikolayYeryomenko commented Aug 7, 2018

I have entity Page with has many HtmlBlocks and entity HtmlBlock with belongs to many pages
(has collection of pages).

I configured many to many relation:

	modelBuilder.Entity<Core.Page>()
                .HasMany(p => p.HtmlBlocks)
                .WithMany(hb => hb.Pages)
                .Map(m =>
                {
                    m.ToTable("PageHtmlBlocks");
                    m.MapLeftKey("PageId");
                    m.MapRightKey("HtmlBlockId");
                });

When I execute:

Core.Page page = _db.Pages.Where(p => p.PageId == pageId).FirstOrDefault();
_db.Entry(page).Collection(p => p.HtmlBlocks)                
                .Load();

this code loads HtmlBlocks related to page.

When I execute:

Core.Page page = _db.Pages.Where(p => p.PageId == pageId).FirstOrDefault();
_db.Entry(page).Collection(p => p.HtmlBlocks)                
		.Query()
                .Load();

this code doesn't load related entities, but generates the same and correct SQL query to fetch data.

I use Entity Framework 6.2
I think this is a bug, please fix this in the future releases.

EF version: 6.2
Database Provider: EntityFramework.SqlServer 6.0.0.0
Operating system: Windows 10 Pro 1803
IDE: Visual Studio 2017 15.6

@ajcvickers
Copy link
Member

EF Team Triage: This is a known limitation of the lower-level implementation of this method and would require significant work to overcome. This issue is not something that our team is planning to address in the EF6.x code base. This does not mean that we would not consider a community contribution to address this issue.

Moving forwards, our team will be fixing bugs, implementing small improvements, and accepting community contributions to the EF6.x code base. Larger feature work and innovation will happen in the EF Core code base (https://github.com/aspnet/EntityFramework).

Closing an issue in the EF6.x project does not exclude us addressing it in EF Core. In fact, a number of popular feature requests for EF have already been implemented in EF Core (alternate keys, batching in SaveChanges, etc.).

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

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

No branches or pull requests

2 participants