NopCommerce 4.1 Lazy Loading

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
Hi,

When I call this code, I notice that there is a brief pause before I receive variable called state.

Order od = _orderService.GetOrderById(1)
string state = od.BillingAddress.StateProvince.Abbreviation;
string country = od.BillingAddress.Country.Name;

Is there a way to disable lazy loading? My goal is to pull a summary of orders per day from nopCommerce. When I enumerate through the orders, it takes about 3 - 4 seconds to pull the state and country.
5 years ago
Each call to GetOrderById() is going to be a separate SQL call (unless order is cached).  If you're 'reporting', then it's better to go directly against the order repository - e.g. see

\Libraries\Nop.Services\Orders\OrderReportService.cs
5 years ago
Hi,

What if I call SearchOrders? I have 50 orders and each time I expand state or country, the code goes back to the database. How do I prevent this behavior?
5 years ago
...go directly against the order repository  ;)
5 years ago
Hi,

I have the same problem. I need to load the Order.BillingAddress.Region and Order.BillingAddress.Country, after the query has run. How do I disable lazy loading on the repository? Is there a setting?
5 years ago
I figured it out:

using Microsoft.EntityFrameworkCore;

            IQueryable<Order> query = orderRepository.Table
                .Include(a => a.BillingAddress.Country)
                .Include(a => a.ShippingAddress.Country)
                .Include(a => a.BillingAddress.StateProvince)
                .Include(a => a.ShippingAddress.StateProvince)
                .Include(a => a.DiscountUsageHistory)
                .Include(a => a.Shipments);
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.