/// <summary> /// We are using just some properties of the entity. Rewrite the properties as JObject field lookups and /// record all the field names used to ensure we only select those. /// </summary> /// <param name="selectExpression">Select expression to re-bind.</param> void RebindPropertiesAndElasticFields(Expression selectExpression) { var projection = MemberProjectionExpressionVisitor.Rebind(SourceType, Mapping, selectExpression); var compiled = Expression.Lambda(projection.Expression, projection.Parameter).Compile(); itemProjector = h => compiled.DynamicInvoke(h); searchRequest.Fields.AddRange(projection.Collected); }
internal static new RebindCollectionResult<string> Rebind(Type sourceType, IElasticMapping mapping, Expression selector) { var parameter = Expression.Parameter(typeof(Hit), "h"); var visitor = new MemberProjectionExpressionVisitor(sourceType, parameter, mapping); Argument.EnsureNotNull("selector", selector); var materializer = visitor.Visit(selector); return new RebindCollectionResult<string>(materializer, visitor.fieldNames, parameter); }
internal static new RebindCollectionResult <string> Rebind(string prefix, IElasticMapping mapping, Expression selector) { var parameter = Expression.Parameter(typeof(Hit), "h"); var visitor = new MemberProjectionExpressionVisitor(prefix, parameter, mapping); Argument.EnsureNotNull("selector", selector); var materializer = visitor.Visit(selector); return(new RebindCollectionResult <string>(materializer, visitor.fieldNames, parameter)); }