4.4 Navigation Properties

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 anni tempo fa
Hi,

I am trying to update a plugin from 4.2 to 4.4. Using the new ORM, how do I translate this entity framework code?

          
 IQueryable<Order> query = GetExpandedOrderTable();
                DateTime beginTime = settings.LastDownloadUtc;
                DateTime endTime = settings.LastDownloadUtcEnd;

                query = query.Where(a => a.CreatedOnUtc >= beginTime);
                query = query.Where(a => a.CreatedOnUtc <= endTime);

                List<int> storeIds = GetStoreIds();

                if (storeIds.Count() > 0)
                    query = query.Where(a => storeIds.Contains(a.StoreId));

                return new PagedList<Order>(query, 0, 1000).ToList();


        /// <summary>
        /// Expands order items and other sub properties.
        /// Increases performance.
        /// </summary>
        /// <returns></returns>
        private IQueryable<Order> GetExpandedOrderTable()
        {
            return orderRepository.Table
                .Include(a => a.OrderItems)
                .Include("OrderItems.Product")
                .Include(a => a.OrderNotes)
                .Include(a => a.GiftCardUsageHistory)
                .Include(a => a.BillingAddress)
                .Include(a => a.BillingAddress.StateProvince)
                .Include(a => a.BillingAddress.Country)
                .Include(a => a.ShippingAddress)
                .Include(a => a.ShippingAddress.StateProvince)
                .Include(a => a.ShippingAddress.Country)
                .Include(a => a.Customer)
                .Include(a => a.DiscountUsageHistory)
                .Include(a => a.Shipments);
        }


How do I get all of these objects?
3 anni tempo fa
From 4.30 nopCommerce use Linq2DB instead of EF

please  check https://docs.nopcommerce.com/en/developer/tutorials/data-access-layer.html

You can check Nop.Services, How Product or others works.

//Sohel
3 anni tempo fa
Hi,

I need to pull a list of orders by date. It must include order items, shipments, and the other objects. It is inefficient to call orderService.GetOrderItemByIdAsync for each order. Is there a better way?
3 anni tempo fa
joe_a84 wrote:
Hi,

I need to pull a list of orders by date. It must include order items, shipments, and the other objects. It is inefficient to call orderService.GetOrderItemByIdAsync for each order. Is there a better way?


Use '_orderService.SearchOrdersAsync' - https://github.com/nopSolutions/nopCommerce/blob/b2a51612bdf7efd0e5023db3dfd80ea2afb79d66/src/Libraries/Nop.Services/Orders/OrderService.cs#L300
3 anni tempo fa
You can get all order items for each order with GetOrderItemsAsync(int orderId,...)

(That's the way ExportOrdersToXmlAsync does it. If you really need to make it more "efficient", you could probably write your own LINQ query)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.