title: Convert Sequence.Generate to Sequence Expression
body: <p>I have the following code that uses Sequence objects to read data from a database table.
  V1 works correctly but since the Seq.generate function is deprecated I receive compiler warnings.</p>
  
  <p>I tried to rerplace this code with V2 (below) but it does not work correctly - 
  basically the reader is opened but only the first record is read - IOW - Read Next does not
  work correctly.</p>
  
  <p>To avoid compilation errors/warnings I need to convert V1 code to use a sequence expression.</p>
  
  <p>Any ideas on the correct approach here. </p>
  
  <p>(BTW - This code is based on examples in Rob Pickering's Beginning F# book - 
  (Data Access/ADO.NET Section).</p>
  
  <pre><code>********************** V1 - Sequence Approach - Deprecated ************************
  
  // execute a command using the Seq.generate
  let execCommand (connName: string) (cmdString: string) = 
      Seq.generate       
          // This function gets called to open a connection and create a reader
          (fun () -&gt; openReader connName cmdString)
          // This function gets called to read a single item in
          // the enumerable for a reader/connection pair
          (fun reader -&gt; readRow(reader))
          (fun reader -&gt; reader.Dispose())
  
  *********************** V2  Alternative - (Does not work) ***************************
  
  let generateSequence connName cmdString =
         seq { // This function gets called to open a connection and
                //create a reader
                use reader = openReader connName cmdString
                // This function gets called to read a single item in
                 // the enumerable for a reader/connection pair
                yield readRow(reader) }
  
  // execute a command using the Seq.generate
  let execCommand (connName: string) (cmdString: string) = 
  
      generateSequence connName cmdString
  
  
  *****************************  Common Functions  **********************************
  
  // Open a db connection
  let openReader connName cmdString =
      let conn = openSQLConnection(connName)
      let cmd = conn.CreateCommand(CommandText=cmdString,
                                   CommandType = CommandType.Text)
      let reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
  
  // read a row from the data reader
  let readRow (reader: #DbDataReader) =
      if reader.Read() then
          let dict = new Dictionary&lt;string, obj&gt;()
          for x in [ 0 .. (reader.FieldCount - 1) ] do
              dict.Add(reader.GetName(x), reader.[x])
          Some(dict)
      else
          None
  </code></pre>