-
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
Query using Include problem #7610
Comments
@sonphnt The include tells EF that for each Member that is loaded the related Team should also be loaded. When that Team is loaded the already loaded Members are added to the collection on Team. In other words, EF isn't loading any more data, it is simply fixing up the references between already loaded data. If you are having issues with JSON serialization, then you might want to look at this: #4646 and this #7564 |
Hi @ajcvickers Thanks for your reply but is there any settings or extensions to avoid "When that Team is loaded the already loaded Members are added to the collection on Team" Because Parsing that collection to Json will include that Members array on Team that will generate a huge Json file unless I have to do manually code to get rid of that collection before returning to client. Thanks |
@sonphnt , I too has found this behavior resulting in a huge JSON object. As the issue is "closed-by-design", I chose to fix it myself by manually setting the
This would result in:
|
Yes. To avoid returning a huge json to client. You should not return entity model like that. You need to cast or convert them to view model or using automapper way. |
Hi Everyone,
I have 2 classes like:
Team and Member
I am using Scaffold-DbContext as Database first. It generates 2 classes with
And I want to get all member in database with Team object to get some information about the team, so I use this query
But the problem when I debug. It also load Members list inside Team entity as well. There are a lot of data.
The object looks like this
How to avoid this and using correctly?
Thank you very much
The text was updated successfully, but these errors were encountered: