@@ -388,6 +388,80 @@ public ExclusiveProjectionBuilder<T> IncludeSpecial<TField>(Expression<Func<T, T
388388 return this ;
389389 }
390390
391+ /// <summary>
392+ /// Specify a field to include in the projection.
393+ /// </summary>
394+ /// <param name="fieldName">The name of the field to include.</param>
395+ /// <returns>The projection builder.</returns>
396+ public ExclusiveProjectionBuilder < T > Slice ( string fieldName , int start , int length = 0 )
397+ {
398+ var projection = new Projection ( ) { FieldName = fieldName , Include = true , SliceStart = start } ;
399+ if ( length > 0 )
400+ {
401+ projection . SliceLength = length ;
402+ }
403+ _projections . Add ( projection ) ;
404+ return this ;
405+ }
406+
407+ /// <summary>
408+ /// Specify a field to include in the projection.
409+ /// </summary>
410+ /// <typeparam name="TField">The type of the field to include.</typeparam>
411+ /// <param name="fieldExpression">The field to include in the projection.</param>
412+ /// <returns>The projection builder.</returns>
413+ public ExclusiveProjectionBuilder < T > Slice < TField > ( Expression < Func < T , TField > > fieldExpression , int start , int length = 0 )
414+ {
415+ var fieldName = fieldExpression . GetMemberNameTree ( ) ;
416+ var projection = new Projection ( ) { FieldName = fieldName , Include = true , SliceStart = start } ;
417+ if ( length > 0 )
418+ {
419+ projection . SliceLength = length ;
420+ }
421+ _projections . Add ( projection ) ;
422+ return this ;
423+ }
424+
425+ /// <summary>
426+ /// Specify a special field to include in the projection.
427+ /// </summary>
428+ /// <param name="fieldName">The name of the field to include.</param>
429+ /// <returns>The projection builder.</returns>
430+ public ExclusiveProjectionBuilder < T > IncludeSpecial ( string fieldName )
431+ {
432+ _projections . Add ( new Projection ( ) { FieldName = fieldName , Include = true } ) ;
433+ return this ;
434+ }
435+
436+ /// <summary>
437+ /// Specify a special field to include in the projection.
438+ /// </summary>
439+ /// <param name="fieldName">The name of the field to include.</param>
440+ /// <returns>The projection builder.</returns>
441+ public ExclusiveProjectionBuilder < T > IncludeSpecial < TField > ( Expression < Func < T , TField > > fieldExpression )
442+ {
443+ var isSpecial = false ;
444+ if ( ExpressionValidator . DoesPropertyHaveAttribute < T , TField , DocumentMappingAttribute > ( fieldExpression ) )
445+ {
446+ isSpecial = true ;
447+ }
448+ if ( ExpressionValidator . DoesPropertyHaveAttribute < T , TField , DocumentIdAttribute > ( fieldExpression ) )
449+ {
450+ isSpecial = true ;
451+ }
452+ var fieldName = fieldExpression . GetMemberNameTree ( ) ;
453+ if ( fieldName == "_id" )
454+ {
455+ isSpecial = true ;
456+ }
457+ if ( ! isSpecial )
458+ {
459+ throw new ArgumentException ( $ "Property '{ fieldName } ' must either have the '{ typeof ( DocumentMappingAttribute ) . Name } ' attribute or be the '{ typeof ( DocumentIdAttribute ) . Name } ' attribute.", nameof ( fieldExpression ) ) ;
460+ }
461+ _projections . Add ( new Projection ( ) { FieldName = fieldName , Include = true } ) ;
462+ return this ;
463+ }
464+
391465 public override IProjectionBuilder Clone ( )
392466 {
393467 var clone = new ExclusiveProjectionBuilder < T > ( ) ;
0 commit comments