23 lines
762 B
C#
23 lines
762 B
C#
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace IRaCIS.Core.Infrastructure.Extention
|
|
{
|
|
public static class QueryableWhereExtension
|
|
{
|
|
public static IQueryable<TEntity> WhereIf<TEntity>(this IQueryable<TEntity> query, [NotNullWhen(true)] bool condition, Expression<Func<TEntity, bool>> filter) where TEntity : class
|
|
{
|
|
return condition ? query.Where(filter) : query;
|
|
}
|
|
|
|
public static IEnumerable<TEntity> WhereIf<TEntity>(this IEnumerable<TEntity> query, bool condition, Func<TEntity, bool> filter) where TEntity : class
|
|
{
|
|
return condition ? query.Where(filter) : query;
|
|
}
|
|
|
|
}
|
|
}
|