1. 程式人生 > >應用程式框架實戰二十五:查詢條件(規約模式應用)

應用程式框架實戰二十五:查詢條件(規約模式應用)

/// <summary> /// 過濾整數段 /// </summary> /// <typeparam name="T">實體型別</typeparam> /// <typeparam name="TProperty">屬性型別</typeparam> /// <param name="source">資料來源</param> /// <param name="propertyExpression">屬性表示式,範例:t => t.Age
</param> /// <param name="min">最小值</param> /// <param name="max">最大值</param> public static IQueryable<T> FilterInt<T, TProperty>( this IQueryable<T> source, Expression<Func<T, TProperty>> propertyExpression, int
? min, int? max ) where T : class,IAggregateRoot { return source.Filter( new IntSegmentCriteria<T, TProperty>( propertyExpression, min, max ) ); } /// <summary> /// 過濾double數值段 /// </summary> /// <typeparam name="T">實體型別</typeparam>
/// <typeparam name="TProperty">屬性型別</typeparam> /// <param name="source">資料來源</param> /// <param name="propertyExpression">屬性表示式,範例:t => t.Age</param> /// <param name="min">最小值</param> /// <param name="max">最大值</param> public static IQueryable<T> FilterDouble<T, TProperty>( this IQueryable<T> source, Expression<Func<T, TProperty>> propertyExpression, double? min, double? max ) where T : class,IAggregateRoot { return source.Filter( new DoubleSegmentCriteria<T, TProperty>( propertyExpression, min, max ) ); } /// <summary> /// 過濾decimal數值段 /// </summary> /// <typeparam name="T">實體型別</typeparam> /// <typeparam name="TProperty">屬性型別</typeparam> /// <param name="source">資料來源</param> /// <param name="propertyExpression">屬性表示式,範例:t => t.Age</param> /// <param name="min">最小值</param> /// <param name="max">最大值</param> public static IQueryable<T> FilterDecimal<T, TProperty>( this IQueryable<T> source, Expression<Func<T, TProperty>> propertyExpression, decimal? min, decimal? max ) where T : class,IAggregateRoot { return source.Filter( new DecimalSegmentCriteria<T, TProperty>( propertyExpression, min, max ) ); } /// <summary> /// 過濾日期段,不包含時間 /// </summary> /// <typeparam name="T">實體型別</typeparam> /// <typeparam name="TProperty">屬性型別</typeparam> /// <param name="source">資料來源</param> /// <param name="propertyExpression">屬性表示式,範例:t => t.Age</param> /// <param name="min">最小值</param> /// <param name="max">最大值</param> public static IQueryable<T> FilterDate<T, TProperty>( this IQueryable<T> source, Expression<Func<T, TProperty>> propertyExpression, DateTime? min, DateTime? max ) where T : class,IAggregateRoot { return source.Filter( new DateSegmentCriteria<T, TProperty>( propertyExpression, min, max ) ); } /// <summary> /// 過濾日期時間段,包含時間 /// </summary> /// <typeparam name="T">實體型別</typeparam> /// <typeparam name="TProperty">屬性型別</typeparam> /// <param name="source">資料來源</param> /// <param name="propertyExpression">屬性表示式,範例:t => t.Age</param> /// <param name="min">最小值</param> /// <param name="max">最大值</param> public static IQueryable<T> FilterDateTime<T, TProperty>( this IQueryable<T> source, Expression<Func<T, TProperty>> propertyExpression, DateTime? min, DateTime? max ) where T : class,IAggregateRoot { return source.Filter( new DateTimeSegmentCriteria<T, TProperty>( propertyExpression, min, max ) ); }