Added possibility to chain includes. (#331)
* Added possibility to chain includes. * Removed interface. * Removed the need for generating GUIDs as ids and added tests.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Helpers.Query;
|
||||
|
||||
namespace Microsoft.eShopWeb.ApplicationCore.Specifications
|
||||
{
|
||||
@@ -26,6 +27,13 @@ namespace Microsoft.eShopWeb.ApplicationCore.Specifications
|
||||
{
|
||||
Includes.Add(includeExpression);
|
||||
}
|
||||
|
||||
protected virtual void AddIncludes<TProperty>(Func<IncludeAggregator<T>, IIncludeQuery<T, TProperty>> includeGenerator)
|
||||
{
|
||||
var includeQuery = includeGenerator(new IncludeAggregator<T>());
|
||||
IncludeStrings.AddRange(includeQuery.Paths);
|
||||
}
|
||||
|
||||
protected virtual void AddInclude(string includeString)
|
||||
{
|
||||
IncludeStrings.Add(includeString);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Helpers.Query;
|
||||
|
||||
namespace Microsoft.eShopWeb.ApplicationCore.Specifications
|
||||
{
|
||||
@@ -7,8 +8,7 @@ namespace Microsoft.eShopWeb.ApplicationCore.Specifications
|
||||
public CustomerOrdersWithItemsSpecification(string buyerId)
|
||||
: base(o => o.BuyerId == buyerId)
|
||||
{
|
||||
AddInclude(o => o.OrderItems);
|
||||
AddInclude($"{nameof(Order.OrderItems)}.{nameof(OrderItem.ItemOrdered)}");
|
||||
AddIncludes(query => query.Include(o => o.OrderItems).ThenInclude(i => i.ItemOrdered));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user