Click here to Skip to main content
13,507,742 members
Rate this:
Please Sign up or sign in to vote.
Hi All,

I want to return only the parent table data but by default db context return data with parent table with child table data. Can create another model and set the parent table data but looking for entity returning only parent table data.

Let me know the direct code how can I get only the parent table data.

Advance thanks,

Arun RV

What I have tried:

Posted 13-Aug-17 4:35am
Updated 13-Aug-17 10:34am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Well. Entity framwork is a repository which will load relations, typically when they're accessed. So if you don't access the related thing it won't get loaded.

But the easy way is to simply return a new type from your Linq. Of cause this can be a predefined transport object populated, or simply declared on the fly.

for instance

_dbContext.MyMainEntityTable.First(a => = whatnot).select(s => new NotTheChildObject{ WantedValue = s.Value1, AnotherWantedValue = s.Value2 });

this will return a new class NotTheChildObject with two members: WantedValue, AnotherWantedValue
arunrv 15-Aug-17 11:35am
Hi Thomas,

Thanks for your answer.
Yes it worked.

Arun RV

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180417.1 | Last Updated 13 Aug 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100