C
C#14mo ago
_vegabyte_

Proper way to access Navigational Properties

Hi, I trying to fetch data including the related data on other table. Is this the best way to to do it?
var regularClients = _context.Clients
.Include(mop => mop.ModeOfPayments)
.Include(abu => abu.AddedByUser)
.Include(rq => rq.Request)
.ThenInclude(user => user.Requestor)
.Include(rq => rq.Request)
.ThenInclude(ap => ap.Approvals)
.ThenInclude(cap => cap.Approver)
.Include(st => st.StoreType)
.Include(fd => fd.FixedDiscounts)
.Include(to => to.Term)
.ThenInclude(tt => tt.Terms)
.Include(to => to.Term)
.ThenInclude(td => td.TermDays)
.Include(ba => ba.BusinessAddress)
.Include(oa => oa.OwnersAddress)
.Include(bc => bc.BookingCoverages)
.Include(fr => fr.FreebiesRequests)
.ThenInclude(fi => fi.FreebieItems)
.ThenInclude(item => item.Items)
.ThenInclude(uom => uom.Uom)
.Include(lf => lf.ListingFees)
.ThenInclude(li => li.ListingFeeItems)
.ThenInclude(item => item.Item)
.ThenInclude(uom => uom.Uom)
.Include(cd => cd.ClientDocuments)
.AsNoTracking();
var regularClients = _context.Clients
.Include(mop => mop.ModeOfPayments)
.Include(abu => abu.AddedByUser)
.Include(rq => rq.Request)
.ThenInclude(user => user.Requestor)
.Include(rq => rq.Request)
.ThenInclude(ap => ap.Approvals)
.ThenInclude(cap => cap.Approver)
.Include(st => st.StoreType)
.Include(fd => fd.FixedDiscounts)
.Include(to => to.Term)
.ThenInclude(tt => tt.Terms)
.Include(to => to.Term)
.ThenInclude(td => td.TermDays)
.Include(ba => ba.BusinessAddress)
.Include(oa => oa.OwnersAddress)
.Include(bc => bc.BookingCoverages)
.Include(fr => fr.FreebiesRequests)
.ThenInclude(fi => fi.FreebieItems)
.ThenInclude(item => item.Items)
.ThenInclude(uom => uom.Uom)
.Include(lf => lf.ListingFees)
.ThenInclude(li => li.ListingFeeItems)
.ThenInclude(item => item.Item)
.ThenInclude(uom => uom.Uom)
.Include(cd => cd.ClientDocuments)
.AsNoTracking();
14 Replies
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
jcotton42
jcotton4214mo ago
do you really need all that data? and all at once?
jcotton42
jcotton4214mo ago
Single vs. Split Queries - EF Core
Translating LINQ queries into single and split SQL queries with Entity Framework Core
_vegabyte_
_vegabyte_OP14mo ago
Yes, this is only client information. But this is read only, Does AsNoTracking() is not a good option?
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
_vegabyte_
_vegabyte_OP14mo ago
I need all the information in the query.
No description
No description
No description
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
_vegabyte_
_vegabyte_OP14mo ago
Here I have filters, Querying everything first then filter based on conditions like this
No description
No description
_vegabyte_
_vegabyte_OP14mo ago
Like registration status : Under review Approved Rejected
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
_vegabyte_
_vegabyte_OP14mo ago
Sorry I posted incomplete code. hehe
_vegabyte_
_vegabyte_OP14mo ago
I try this method and it's working fine. Since someone suggest to use AsSplitQuery() what is the best one to use?
No description
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
jcotton42
jcotton4214mo ago
the page I linked explains when/why you'd use AsSplitQuery

Did you find this page helpful?