I'm trying out the EF 4.0 and using the Model first approach. I'd like to store images into the database and I'm not sure of the best type for the scalar in the entity.
I currently have it(the image scalar type) setup as a binary. From what I have been reading the best way to store the image in the db is a byte[]. So I'm assuming that binary is the way to go. If there is a better way I'd switch.
In my controller I have:
//file from client to store in the db
HttpPostedFileBase file = Request.Files[inputTagName];
if (file.ContentLength > 0)
{
keyToAdd.Image = new byte[file.ContentLength];
file.InputStream.Write(keyToAdd.Image, 0, file.ContentLength);
}
This builds fine but when I run it I get an exception writing the stream to keyToAdd.Image.
The exception is something like: Method does not exist.
Any ideas?
Note that when using a EF 4.0 model first approach I only have int16, int32, double, string, decimal, binary, byte, DateTime, Double, Single, and SByte as available types.
Thanks