Esempio n. 1
0
        /// <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&lt;System.Int32&gt;.</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));
        }
Esempio n. 2
0
    /// <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);
    }
Esempio n. 3
0
        /// <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&lt;System.String&gt;.</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));
        }
Esempio n. 4
0
 /// <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));
 }
Esempio n. 5
0
 /// <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));
 }
Esempio n. 6
0
 /// <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;
 }
Esempio n. 7
0
 /// <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.");
 }