// ReSharper restore UnusedMember.Global // Constructors public ItemMaterializationContext(MaterializationContext materializationContext, Session session) { MaterializationContext = materializationContext; Session = session; typeIdRegistry = session.StorageNode.TypeIdRegistry; entities = new Entity[materializationContext.EntitiesInRow]; }
// ReSharper restore UnusedMember.Global // Constructors public ItemMaterializationContext(MaterializationContext materializationContext, ParameterContext parameterContext) { ParameterContext = parameterContext; MaterializationContext = materializationContext; Session = materializationContext.Session; typeIdRegistry = Session.StorageNode.TypeIdRegistry; entities = new Entity[materializationContext.EntitiesInRow]; }
/// <summary> /// Wraps <see cref="RecordSetReader"/> by adding <see cref="Tuple"/> to <typeparamref name="TResult"/> /// conversion for individual records. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="recordSetReader">The reader over raw data source.</param> /// <param name="context">The context.</param> /// <param name="parameterContext">The parameter context.</param> /// <param name="itemMaterializer">The materialization delegate performing /// <see cref="Tuple"/> instance to instance of <typeparamref name="TResult"/> type conversion.</param> public static object Materialize <TResult>( RecordSetReader recordSetReader, MaterializationContext context, ParameterContext parameterContext, IItemMaterializer <TResult> itemMaterializer) { var enumerationContext = (EnumerationContext)recordSetReader.Context; if (enumerationContext != null) { enumerationContext.MaterializationContext = context; } return(new MaterializingReader <TResult>(recordSetReader, context, parameterContext, itemMaterializer)); }
internal MaterializingReader(RecordSetReader recordSetReader, MaterializationContext context, ParameterContext parameterContext, IItemMaterializer <TItem> itemMaterializer) { this.recordSetReader = recordSetReader; this.context = context; this.parameterContext = parameterContext; this.itemMaterializer = itemMaterializer; if (context.MaterializationQueue == null) { context.MaterializationQueue = materializationQueue = new Queue <Action>(); } else { materializationQueue = null; } }
public override TResult?Materialize(Tuple tuple, MaterializationContext context, ParameterContext parameterContext) { var result = base.Materialize(tuple, context, parameterContext); return(aggregateType == AggregateType.Sum ? result ?? default : result); }
public virtual TItem Materialize(Tuple tuple, MaterializationContext context, ParameterContext parameterContext) => materializationDelegate.Invoke(tuple, new ItemMaterializationContext(context, parameterContext));
private static IEnumerable <TResult> BatchMaterialize <TResult>(IEnumerable <TResult> materializedSequence, MaterializationContext context, ParameterContext parameterContext) { var materializationQueue = new Queue <Action>(); var batchActivator = new BatchActivator(materializationQueue, parameterContext); context.MaterializationQueue = materializationQueue; var batchSequence = materializedSequence .Batch(BatchFastFirstCount, BatchMinSize, BatchMaxSize) .ApplyBeforeAndAfter(batchActivator.Activate, batchActivator.Deactivate); return(batchSequence.SelectMany(batch => batch)); }
/// <summary> /// Materializes the specified data source. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="dataSource">The data source.</param> /// <param name="context">The context.</param> /// <param name="parameterContext">The parameter context.</param> /// <param name="itemMaterializer">The item materializer.</param> /// <param name="tupleParameterBindings">The tuple parameter bindings.</param> public static IEnumerable <TResult> Materialize <TResult>(IEnumerable <Tuple> dataSource, MaterializationContext context, ParameterContext parameterContext, Func <Tuple, ItemMaterializationContext, TResult> itemMaterializer, Dictionary <Parameter <Tuple>, Tuple> tupleParameterBindings) { using (parameterContext.Activate()) foreach (var tupleParameterBinding in tupleParameterBindings) { tupleParameterBinding.Key.Value = tupleParameterBinding.Value; } var session = context.Session; var recordSet = dataSource as RecordSet; if (recordSet != null) { var enumerationContext = (EnumerationContext)recordSet.Context; enumerationContext.MaterializationContext = context; } var materializedSequence = dataSource .Select(tuple => itemMaterializer.Invoke(tuple, new ItemMaterializationContext(context, session))); return(context.MaterializationQueue == null ? BatchMaterialize(materializedSequence, context, parameterContext) : SubqueryMaterialize(materializedSequence, parameterContext)); }