+2  A: 

The View looks fine, I just use src="/Controller/GetImage?id=xxxxx" which is effectively the same. The Controller action is a little different in that it's returning a FileContentResult thus. My image in the DB also stores the MIME type, the images are uploaded to the server so I just grab that at upload time.

    public FileContentResult GetImage(Guid ImageID)
    {
        Image image = (from i in myRepository.Images
                       where i.ImageID == ImageID
                       select i).SingleOrDefault();
        if (image == null)
        {

            return File(System.IO.File.ReadAllBytes(Server.MapPath("/Content/Images/nophoto.png")), "image/png");
        }
        else
        {
            return File(image.ImageBlob, image.ImageMimeType);
        }
    }

Code to the Image class

[Table(Name="Images")]
public class Image
{
    [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
    public Guid ImageID { get; set; }
    [Column]
    public bool OnDisk { get; set; }
    [Column]
    public string ImagePath { get; set; }
    [Column]
    public byte[] ImageBlob { get; set; }
    [Column]
    public string ImageMimeType { get; set; }
    [Column(AutoSync = AutoSync.Always, DbType = "rowversion NOT NULL", CanBeNull = false, IsDbGenerated = true, IsVersion = true)]
    public Binary ConcurrencyStamp { get; set; }
}
Lazarus
What type is Image? Not the one from System.Drawing, correct?
Geoffrey Chetwood
Absolutely, it's a Linq to SQL class. I'll paste the code above.
Lazarus
A: 

Using Lazurus' answer, I have come up with the following solution. I like his approach, but for simplicity's sake, I am using this to get started and I think it is the best (for now) to help other's understand it.

Any better answers are welcome, as well as criticisms about this code since I know it is not very elegant at all.

public FileContentResult ShowImage(long ID) {
    return File( _db.Vehicles.First(m => m.ID == ID).Picture, MediaTypeNames.Image.Jpeg);
}
Geoffrey Chetwood
You don't need to initialise the Image to byte[0], just byte[] will do. You are then looping over the List when it would be better to use a query to just return a single element (just in case you get a second match). Also if v.Picture is a byte[] then just return that which would also end the loop and save needless iterations, i.e. return File(v.Picture, System.Net.Mime.MediaTypeNames.Image.Jpeg); rather than the Image = v.Picture;. Lastly, you'll notice that I returned a default image, something that's worth considering as otherwise you could end up with the missing image icon.
Lazarus
@Laz: byte[] Image = new byte[]; -- Array creation must have array size or array initializer
Geoffrey Chetwood
@Laz: If I knew how to do the query in EF, I totally would. I am just too new to figure it out on my own yet. That is where I could use help.
Geoffrey Chetwood
I think that should be much better now.
Geoffrey Chetwood