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

.net ef-code-first entity-framework sql-server-2008

Question

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.

1
83
1/11/2011 12:38:59 AM

Accepted Answer

You can't use SQL FILESTREAM in EF. EF is supposed to work on top of different database servers but filestream feature is specific feature of SQL 2008 and newer. You can try to do it old way - use varbinary(max) in your database table and use byte array in your mapped class.

Edit:

Little clarification - you can use FILESTREAM in the database but EF will not take advantage of streaming. It will load it as standard varbinary(max).

42
6/5/2011 6:53:23 AM

Popular Answer

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; }
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow