The ObjectMapper .NET Project

Official blog of the AdFactum ObjectMapper .NET

How to store binary data (blob)

Posted by Gerhard Stephan on April 23rd, 2007

The ObjectMapper .NET knows 3 different ways to store binary data (blobs) in database. Two ways are designed to store binary blobs and one to store character blobs.

The straightest way to store binary data is to create a byte array property. This byte array property could look like:

        /// <summary>

        /// Gets or sets the BLOB.

        /// </summary>

        /// <value>The BLOB.</value>

        [PropertyName("Stream")]

        public byte[] Blob

        {

            get { return blob; }

            set { blob = value; }

        }

 

As a second solution the AdFactum ObjectMapper .NET offers you the possibility to use Streams. 

        /// <summary>

        /// Gets or sets the BLOB.

        /// </summary>

        /// <value>The BLOB.</value>

        [PropertyName("Stream")]

        public Stream Stream

        {

            get { return stream; }

            set { stream = value; }

        }

 

When reading from database the ObjectMapper .NET creates a Memory Stream for the blob content.

A third solution is to use character blobs. In oracle known as CBLOB or known as a MEMO field if you’re using Microsoft Access. Such character blobs are defined as regular strings with an unlimited property length.

        /// <summary>

        /// Gets or sets the content.

        /// </summary>

        /// <value>The content.</value>

        [PropertyLength(int.MaxValue)]

        public string Content

        {

            get { return content; }

            set { content = value; }

        }

 

So, that’s all you have to know about blobs if you’re using the AdFactum ObjectMapper .NET.
Hope you enjoy the simplicity.

Cheers
- Gerhard 

kick it on DotNetKicks.com

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>