How to make streams from BLOBs available in plain old C# objects when using SqlDataReader?

前端 未结 3 1467
小鲜肉
小鲜肉 2021-02-04 13:48

This is the scenario:

  • We store files, e.g. relatively large documents (10-300MB), in blobs in our MSSQL database.
  • We have a very small domain model so we
3条回答
  •  被撕碎了的回忆
    2021-02-04 14:08

    There's a bug; you are ignoring the user's args, and you should probably guard for -ve returned:

      public override int Read(byte[] buffer, int index, int count)
      {
         long returned = dataReader.GetBytes(0, currentPosition,
             buffer, 0, buffer.Length);
         currentPosition += returned;
         return Convert.ToInt32(returned);
      }
    

    should probably be:

      public override int Read(byte[] buffer, int index, int count)
      {
         long returned = dataReader.GetBytes(0, currentPosition,
             buffer, index, count);
         if(returned > 0) currentPosition += returned;
         return (int)returned;
      }
    

    (otherwise you are writing into the wrong part of the buffer)

    But generally looks good.

提交回复
热议问题