/// <summary> /// Creates a new instance of the <see cref="SqlFileStreamReadStream" /> class with the specified connection, table, /// data field, and where criteria action. /// </summary> /// <param name="connection">The <see cref="IDbConnection" /> to use.</param> /// <param name="table">The table in which the data is stored.</param> /// <param name="dataField">The field in which the data is stored</param> /// <param name="criteriaAction">The <see cref="BuildWhereCriteriaAction"/> to use to generate criteria that identifies the record.</param> public SqlFileStreamReadStream(IDbConnection connection, string table, string dataField, BuildWhereCriteriaAction criteriaAction) : base(connection, OpenConnectionAndBeginTransaction(connection)) { // TODO: add buffering try { using (SqlCommand cmd = ((SqlConnection)Connection).CreateCommand()) { cmd.CommandText = "SELECT " + dataField + ".PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT() FROM " + table + " WHERE " + criteriaAction(cmd); cmd.Transaction = (SqlTransaction)Transaction; using (SqlDataReader rd = cmd.ExecuteReader(CommandBehavior.SingleRow)) { rd.Read(); string path = rd.GetString(0); byte[] context = (byte[])rd.GetValue(1); // todo: fileoptions, allocationsize _innerStream = new SqlFileStream(path, context, FileAccess.Read); } } } catch { if (_innerStream != null) _innerStream.Dispose(); base.Close(); // TODO: cleanup throw; } }