-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Circular References #4646
Comments
You probably should serialize a ViewModel that doesn't have reference loop (anyway using DTO is the way to go) and not the entities or setting
As I commented on the MVC issue. |
A lot of developers have the same problem and spend his time. @microsoft: Why one don't make the setting |
Yes, a default that throws an exception when used might not be the best option... 😕 |
@capesean EF will always fix up navigation properties for everything that you bring into memory. So loading projects with their respective clients will always result in the client navigation properties pointing back to projects that are assigned to them (only the ones that are in memory... it won't go and fetch the additional ones from the database unless you tell it to). What I'm not sure about is why this has only just started failing for you. EF has always had this behavior (right from its first release). It was missing from some of the early EF7 betas, but it's been there for the last few pre-releases. Was it RC1 that you upgraded from? |
Hi Rowan I've been using RC2 and it's been working like a dream until I changed recently to EFC1.0 - I'm not sure what the possibility that I've been using an early EF7 build is. But just to clarify: I do use DTOs and I also have been using But leave it with me for now as I'm trying to reproduce it in a simple standalone project which I can then share with you. At the moment I'm struggling to get migrations working (Failed to initialize CoreCLR) but once I've got that fixed I'll try reproduce. |
@rowanmiller I don't think his problem is with EF but with MVC 6. |
EF shouldn't populate each client with all the projects it has... but it should populate the collection with the ones that are being loaded by your query. I'm going to close this one out, since the issue with the serialization loop is an MVC thing and you have aspnet/Mvc#4160 open on that front. Feel free to open a new issue (or re-open this one) if you have a repro that shows EF doing the wrong thing with Include. |
My model is effectively:
Up until I changed to the EntityFrameworkCore, I could fetch Projects with their associated Clients:
DbContext.Projects.Include(p => p.Client);
Since upgrading, I'm getting the error:
Additional information: Self referencing loop detected with type 'Models.Project'. Path 'Client.Projects'.
This should be pretty straight-forward: give me the Projects and their Clients. I don't want the Clients' Projects - else then I could see the issue with the loop.
I've mentioned this here:
aspnet/Mvc#4160
The text was updated successfully, but these errors were encountered: