Click here to Skip to main content
14,970,304 members
Please Sign up or sign in to vote.
1.00/5 (1 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:

Updated 13-Aug-17 10:34am

1 solution

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)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900