/// <summary> /// Materializes the output as a CSV formatted string. /// </summary> /// <typeparam name="TCommand">The type of the t command.</typeparam> /// <typeparam name="TParameter">The type of the t parameter.</typeparam> /// <param name="commandBuilder">The command builder.</param> /// <param name="outputStream">The output stream.</param> /// <param name="desiredColumns">The properties of this type will be used to determine the desired columns..</param> /// <param name="csvSerializer">Optional CSV serializer. Used to override how non-null values are converted into strings.</param> /// <param name="includeHeaders">if set to <c>true</c> [include headers].</param> /// <returns>ILink<System.Int32>.</returns> public static ILink <int> ToCsv <TCommand, TParameter>(this SingleRowDbCommandBuilder <TCommand, TParameter> commandBuilder, TextWriter outputStream, Type desiredColumns, CsvSerializer csvSerializer = null, bool includeHeaders = true) where TCommand : DbCommand where TParameter : DbParameter { if (commandBuilder == null) { throw new ArgumentNullException(nameof(commandBuilder), $"{nameof(commandBuilder)} is null."); } if (outputStream == null) { throw new ArgumentNullException(nameof(outputStream), $"{nameof(outputStream)} is null."); } if (desiredColumns == null) { throw new ArgumentNullException(nameof(desiredColumns), $"{nameof(desiredColumns)} is null."); } var columnsFor = MetadataCache.GetMetadata(desiredColumns).ColumnsFor; if (columnsFor.Length == 0) { throw new MappingException($"Type {desiredColumns.Name} has no writable columns."); } return(new CsvStreamMaterializer <TCommand, TParameter>(commandBuilder, outputStream, csvSerializer ?? new CsvSerializer(), includeHeaders, columnsFor)); }
/// <summary> /// This is the constructor to use when you want a MasterDetailObjectOrNull materializer /// </summary> public MasterDetailCollectionMaterializer(SingleRowDbCommandBuilder <TCommand, TParameter> commandBuilder, string masterKeyColumn, Func <TMaster, ICollection <TDetail> > map, RowOptions masterOptions, CollectionOptions detailOptions) : //We're taking advantage of the fact that the RowOptions/CollectionOptions flags are in the same position. this(commandBuilder, masterKeyColumn, map, (CollectionOptions)((int)masterOptions & (int)CollectionOptions.InferConstructor), detailOptions) { m_DiscardExtraRows = masterOptions.HasFlag(RowOptions.DiscardExtraRows); m_PreventEmptyResults = masterOptions.HasFlag(RowOptions.PreventEmptyResults); }
/// <summary> /// Materializes the output as a CSV formatted string. /// </summary> /// <typeparam name="TCommand">The type of the t command.</typeparam> /// <typeparam name="TParameter">The type of the t parameter.</typeparam> /// <param name="commandBuilder">The command builder.</param> /// <param name="csvSerializer">Optional CSV serializer. Used to override how non-null values are converted into strings.</param> /// <param name="includeHeaders">if set to <c>true</c> [include headers].</param> /// <param name="desiredColumns">The desired columns. If null, all columns are returned.</param> /// <returns>ILink<System.String>.</returns> public static ILink <string> ToCsv <TCommand, TParameter>(this SingleRowDbCommandBuilder <TCommand, TParameter> commandBuilder, IReadOnlyList <string> desiredColumns = null, CsvSerializer csvSerializer = null, bool includeHeaders = true) where TCommand : DbCommand where TParameter : DbParameter { if (commandBuilder == null) { throw new ArgumentNullException(nameof(commandBuilder), $"{nameof(commandBuilder)} is null."); } return(new CsvStringMaterializer <TCommand, TParameter>(commandBuilder, csvSerializer ?? new CsvSerializer(), includeHeaders, desiredColumns)); }
/// <summary> /// Allows compilation of the ToObject materializer. /// </summary> /// <typeparam name="TCommand">The type of the command.</typeparam> /// <typeparam name="TParameter">The type of the parameter.</typeparam> /// <param name="commandBuilder">The command builder.</param> /// <returns></returns> public static CompiledSingleRow <TCommand, TParameter> Compile <TCommand, TParameter>(this SingleRowDbCommandBuilder <TCommand, TParameter> commandBuilder) where TCommand : DbCommand where TParameter : DbParameter { return(new CompiledSingleRow <TCommand, TParameter>(commandBuilder)); }
/// <summary> /// Allows compilation of the ToObject materializer. /// </summary> /// <typeparam name="TCommand">The type of the command.</typeparam> /// <typeparam name="TParameter">The type of the parameter.</typeparam> /// <typeparam name="TObject">The type of the object to be constructed.</typeparam> /// <param name="commandBuilder">The command builder.</param> /// <returns></returns> public static CompiledSingleRow <TCommand, TParameter, TObject> Compile <TCommand, TParameter, TObject>(this SingleRowDbCommandBuilder <TCommand, TParameter, TObject> commandBuilder) where TCommand : DbCommand where TParameter : DbParameter where TObject : class, new() { return(new CompiledSingleRow <TCommand, TParameter, TObject>(commandBuilder)); }
/// <summary> /// Initializes a new instance of the <see cref="CompiledMultipleRow{TCommand, TParameter}"/> struct. /// </summary> /// <param name="commandBuilder">The command builder.</param> public CompiledSingleRow(SingleRowDbCommandBuilder <TCommand, TParameter> commandBuilder) { m_CommandBuilder = commandBuilder; }
/// <summary> /// Initializes a new instance of the <see cref="SingleRowDbCommandBuilder{TCommand, TParameter, TObject}"/> class. /// </summary> /// <param name="commandBuilder">The command builder.</param> /// <exception cref="System.ArgumentNullException">commandBuilder</exception> public SingleRowDbCommandBuilder(SingleRowDbCommandBuilder <TCommand, TParameter> commandBuilder) : base(commandBuilder?.DataSource ?? throw new ArgumentNullException(nameof(commandBuilder), $"{nameof(commandBuilder)} is null.")) { m_CommandBuilder = commandBuilder ?? throw new ArgumentNullException(nameof(commandBuilder), $"{nameof(commandBuilder)} is null."); }