Click here to Skip to main content
13,259,976 members (50,099 online)
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,


Regards,
Arun RV

What I have tried:

_dbContext.TestResults.ToArray();
Posted 13-Aug-17 5:35am
arunrv2.6K
Updated 13-Aug-17 11:34am

1 solution

Rate this: bad
 
good
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 => a.id = whatnot).select(s => new NotTheChildObject{ WantedValue = s.Value1, AnotherWantedValue = s.Value2 });

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

Thanks for your answer.
Yes it worked.

Thanks,
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 |
Web04 | 2.8.171114.1 | Last Updated 13 Aug 2017
Copyright © CodeProject, 1999-2017
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