Reputation: 4144
I am upgrading a website that used Entity Framework and now uses Linq2Db. I notice Linq2Db has no navigation properties. How would I translate this code from Entity Framework? I need to return an order with a list of order items, shipments, and other related objects. I am unable to query order items, shipments, and the other objects one by one.
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);
}`
Upvotes: 0
Views: 319
Reputation: 89091
EF Navigation Property => linq2db Association
EF Eager Loading Include() => linq2db LoadWith()
Upvotes: 1