zeroframework/Services/DeviceCenter/ZeroFramework.DeviceCenter.Domain/Specifications/Builder/IncludableBuilderExtensions.cs

36 lines
1.7 KiB
C#
Raw Normal View History

2023-12-05 09:22:48 +00:00
using System.Linq.Expressions;
namespace ZeroFramework.DeviceCenter.Domain.Specifications.Builder
{
public static class IncludableBuilderExtensions
{
public static IIncludableSpecificationBuilder<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>(
this IIncludableSpecificationBuilder<TEntity, TPreviousProperty> previousBuilder,
Expression<Func<TPreviousProperty, TProperty>> thenIncludeExpression)
where TEntity : class
{
var info = new IncludeExpressionInfo(thenIncludeExpression, typeof(TEntity), typeof(TProperty), typeof(TPreviousProperty));
((List<IncludeExpressionInfo>)previousBuilder.Specification.IncludeExpressions).Add(info);
var includeBuilder = new IncludableSpecificationBuilder<TEntity, TProperty>(previousBuilder.Specification);
return includeBuilder;
}
public static IIncludableSpecificationBuilder<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>(
this IIncludableSpecificationBuilder<TEntity, IEnumerable<TPreviousProperty>> previousBuilder,
Expression<Func<TPreviousProperty, TProperty>> thenIncludeExpression)
where TEntity : class
{
var info = new IncludeExpressionInfo(thenIncludeExpression, typeof(TEntity), typeof(TProperty), typeof(TPreviousProperty));
((List<IncludeExpressionInfo>)previousBuilder.Specification.IncludeExpressions).Add(info);
var includeBuilder = new IncludableSpecificationBuilder<TEntity, TProperty>(previousBuilder.Specification);
return includeBuilder;
}
}
}