How to store images using Entity Framework Code First CTP 5?

Max Schmeling picture Max Schmeling · Jan 11, 2011 · Viewed 75.3k times · Source

I'm just trying to figure out if there is a simple way to store and retrieve binary (file) data using EF Code First CTP 5? I would really like it to use the FILESTREAM type, but I'm really just looking for some way to make it work.

Answer

nima picture nima · Jun 5, 2011

I always create another class like ProductImage with a one-to-one association in order to manage lazy loading and also to normalize the table:

public class ProductImage
{
    public int ProductId { get; private set; }
    public byte[] Image { get; set; }
}