Ejemplo n.º 1
0
 /// <summary>
 /// Materializes the result as an instance of the indicated type
 /// </summary>
 /// <param name="rowOptions">The row options.</param>
 /// <returns></returns>
 public ILink <TObject?> ToObjectOrNull(RowOptions rowOptions = RowOptions.None)
 {
     return(new CompiledObjectOrNullMaterializer <TCommand, TParameter, TObject>(m_CommandBuilder, rowOptions));
 }
Ejemplo n.º 2
0
 /// <summary>Initializes a new instance of the <see cref="Tortuga.Chain.Materializers.DataRowMaterializer{TCommand, TParameter}"/> class.</summary>
 /// <param name="commandBuilder">The command builder.</param>
 /// <param name="rowOptions">The row options.</param>
 public DataRowMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder, RowOptions rowOptions)
     : base(commandBuilder)
 {
     m_RowOptions = rowOptions;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Materializes the result as an instance of the indicated type
 /// </summary>
 /// <typeparam name="TResultObject">The type of the object returned.</typeparam>
 /// <param name="rowOptions">The row options.</param>
 /// <returns></returns>
 public ILink <TResultObject> ToObject <TResultObject>(RowOptions rowOptions = RowOptions.None)
     where TResultObject : class, new()
 {
     return(new CompiledObjectMaterializer <TCommand, TParameter, TResultObject>(m_CommandBuilder, rowOptions));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Materializes the result as a master object with detail records.
 /// </summary>
 /// <typeparam name="TDetail">The type of the detail model.</typeparam>
 /// <param name="masterKeyColumn">The column used as the primary key for the master records.</param>
 /// <param name="map">This is used to identify the detail collection property on the master object.</param>
 /// <param name="masterOptions">Options for handling extraneous rows and constructor selection for the master object.</param>
 /// <param name="detailOptions">Options for handling constructor selection for the detail objects</param>
 /// <returns></returns>
 public IMasterDetailMaterializer <TObject?> ToMasterDetailObjectOrNull <TDetail>(string masterKeyColumn, Func <TObject, ICollection <TDetail> > map, RowOptions masterOptions = RowOptions.None, CollectionOptions detailOptions = CollectionOptions.None)
     where TDetail : class
 {
     return(ToMasterDetailObjectOrNull <TObject, TDetail>(masterKeyColumn, map, masterOptions, detailOptions));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Materializes the result as an instance of the indicated type
 /// </summary>
 /// <param name="rowOptions">The row options.</param>
 /// <returns>IConstructibleMaterializer&lt;TObject&gt;.</returns>
 public IConstructibleMaterializer <TObject?> ToObjectOrNull(RowOptions rowOptions = RowOptions.None)
 {
     return(m_CommandBuilder.ToObjectOrNull <TObject>(rowOptions));
 }
Ejemplo n.º 6
0
    /// <summary>
    /// Initializes a new instance of the <see
    /// cref="Tortuga.Chain.Materializers.ObjectMaterializer{TCommand, TParameter, TObject}"/> class.
    /// </summary>
    /// <param name="commandBuilder">The command builder.</param>
    /// <param name="rowOptions">The row options.</param>
    /// <exception cref="MappingException">
    /// Type {typeof(TObject).Name} has does not have any non-default constructors. or Type
    /// {typeof(TObject).Name} has more than one non-default constructor. Please use the
    /// WithConstructor method to specify which one to use.
    /// </exception>
    public ObjectOrNullMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder, RowOptions rowOptions)
        : base(commandBuilder)
    {
        m_RowOptions = rowOptions;

        if (m_RowOptions.HasFlag(RowOptions.InferConstructor))
        {
            var constructors = ObjectMetadata.Constructors.Where(x => x.Signature.Length > 0).ToList();
            if (constructors.Count == 0)
            {
                throw new MappingException($"Type {typeof(TObject).Name} has does not have any non-default constructors.");
            }
            if (constructors.Count > 1)
            {
                throw new MappingException($"Type {typeof(TObject).Name} has more than one non-default constructor. Please use the WithConstructor method to specify which one to use.");
            }
            Constructor = constructors[0];
        }
    }
 /// <summary>
 /// Indicates the results should be materialized as a Row.
 /// </summary>
 public ILink <Row> ToRow(RowOptions rowOptions = RowOptions.None) => new RowMaterializer <TCommand, TParameter>(this, rowOptions);
 /// <summary>
 /// Materializes the result as an instance of the indicated type
 /// </summary>
 /// <typeparam name="TObject">The type of the object returned.</typeparam>
 /// <param name="rowOptions">The row options.</param>
 /// <returns></returns>
 public IConstructibleMaterializer <TObject> ToObject <TObject>(RowOptions rowOptions = RowOptions.None)
     where TObject : class
 {
     return(new ObjectMaterializer <TCommand, TParameter, TObject>(this, rowOptions));
 }
 /// <summary>
 /// Materializes the result as a dynamic object
 /// </summary>
 /// <param name="rowOptions">The row options.</param>
 /// <returns></returns>
 public ILink <dynamic> ToDynamicObject(RowOptions rowOptions = RowOptions.None) => new DynamicObjectMaterializer <TCommand, TParameter>(this, rowOptions);
Ejemplo n.º 10
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);
    }